Repository: parcel-bundler/parcel
File: packages/core/core/src/requests/TargetRequest.js (JavaScript)

Code before:
export function skipTarget(
  targetName: string,
  exclusiveTarget?: FilePath,
  descriptorSource?: FilePath | Array<FilePath>,
): boolean {
  //  We skip targets if they have a descriptor.source and don't match the current exclusiveTarget
  //  They will be handled by a separate resolvePackageTargets call from their Entry point
  //  but with exclusiveTarget set.

  return exclusiveTarget == null
    ? descriptorSource != null
    : targetName !== exclusiveTarget;
}

async function run({input, api, options}: RunOpts) {
  let targetResolver = new TargetResolver(
    api,
    optionsProxy(options, api.invalidateOnOptionChange),
  );
  let targets = await targetResolver.resolve(input.packagePath, input.target);

  for (const currTarget of targets) {
    if (
      currTarget.name !== 'default' &&
      currTarget.distEntry != null &&
      currTarget.distDir + '/' + currTarget.distEntry === input.filePath
    ) {
      throw new ThrowableDiagnostic({
        diagnostic: {
          message: 'Target is configured to overwrite source code.',
          hints: [
            'Are package.json target fields (possibly main, module, browser, or distDir) different from the source files?',
            'Please see www.v2.parceljs.org/configuration/package-json for more information.',
          ],
        },
      });
    }
  }

  let configResult = nullthrows(
    await api.runRequest<null, ConfigAndCachePath>(createParcelConfigRequest()),
  );
  let parcelConfig = getCachedParcelConfig(configResult, options);

  // Find named pipelines for each target.
  let pipelineNames = new Set(parcelConfig.getNamedPipelines());
  for (let target of targets) {
    if (pipelineNames.has(target.name)) {
      target.pipeline = target.name;
    }
  }

Review comment (suggestion):
not sure if this'll help in resolving the windows test case issue but you probably want to use path utils for this, something like `path.join(currTarget.distDir, currTarget.distEntry) === input.filePath` or even `path.join(currTarget.distDir, currTarget.distEntry) === path.normalize(input.filePath)`

Code after:
    extensions: ['.d.ts'],
  },
};

export type TargetRequest = {|
  id: string,
  +type: 'target_request',
  run: RunOpts => Async<Array<Target>>,
  input: Entry,
|};

const type = 'target_request';

export default function createTargetRequest(input: Entry): TargetRequest {
  return {
    id: `${type}:${hashObject(input)}`,
    type,
    run,
    input,
  };
}

export function skipTarget(
  targetName: string,
  exclusiveTarget?: FilePath,
  descriptorSource?: FilePath | Array<FilePath>,
): boolean {
  //  We skip targets if they have a descriptor.source and don't match the current exclusiveTarget
  //  They will be handled by a separate resolvePackageTargets call from their Entry point
  //  but with exclusiveTarget set.

  return exclusiveTarget == null
    ? descriptorSource != null
    : targetName !== exclusiveTarget;
}

async function run({input, api, options}: RunOpts) {
  let targetResolver = new TargetResolver(
    api,
    optionsProxy(options, api.invalidateOnOptionChange),
  );
  let targets: Array<Target> = await targetResolver.resolve(
    fromProjectPath(options.projectRoot, input.packagePath),
    input.target,
  );

  assertTargetsAreNotEntries(targets, input, options);

  let configResult = nullthrows(
    await api.runRequest<null, ConfigAndCachePath>(createParcelConfigRequest()),
  );