diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 23ae62d7b0c5..752d89ac336a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,8 @@ jobs: - job: Windows - pool: 'Hosted VS2017' + pool: + vmImage: 'vs2017-win2016' variables: os_name: Windows diff --git a/packages/berry-core/sources/scriptUtils.ts b/packages/berry-core/sources/scriptUtils.ts index 77b8f60d2d28..faf6ae11b23d 100644 --- a/packages/berry-core/sources/scriptUtils.ts +++ b/packages/berry-core/sources/scriptUtils.ts @@ -1,4 +1,4 @@ -import {CwdFS, ZipOpenFS, xfs} from '@berry/fslib'; +import {CwdFS, ZipOpenFS, xfs, NodeFS} from '@berry/fslib'; import {execute} from '@berry/shell'; import {delimiter, posix} from 'path'; import {PassThrough, Readable, Writable} from 'stream'; @@ -22,16 +22,19 @@ async function makePathWrapper(location: string, name: string, argv0: string, ar } export async function makeScriptEnv(project: Project) { - const scriptEnv = {... process.env}; + const scriptEnv: {[key: string]: string} = {}; + for (const key of Object.keys(process.env)) + scriptEnv[key.toUpperCase()] = process.env[key] as string; + const binFolder = scriptEnv.BERRY_BIN_FOLDER = dirSync().name; // Register some binaries that must be made available in all subprocesses // spawned by Berry - await makePathWrapper(binFolder, `run`, process.execPath, [process.argv[1], `run`]), - await makePathWrapper(binFolder, `yarn`, process.execPath, [process.argv[1]]), - await makePathWrapper(binFolder, `yarnpkg`, process.execPath, [process.argv[1]]), - await makePathWrapper(binFolder, `node`, process.execPath), + await makePathWrapper(binFolder, `run`, process.execPath, [process.argv[1], `run`]); + await makePathWrapper(binFolder, `yarn`, process.execPath, [process.argv[1]]); + await makePathWrapper(binFolder, `yarnpkg`, process.execPath, [process.argv[1]]); + await makePathWrapper(binFolder, `node`, process.execPath); scriptEnv.PATH = scriptEnv.PATH ? `${binFolder}${delimiter}${scriptEnv.PATH}` @@ -40,7 +43,7 @@ export async function makeScriptEnv(project: Project) { // Add the .pnp.js file to the Node options, so that we're sure that PnP will // be correctly setup - const pnpPath = `${project.cwd}/.pnp.js`; + const pnpPath = NodeFS.fromPortablePath(`${project.cwd}/.pnp.js`); const pnpRequire = `--require ${pnpPath}`; if (xfs.existsSync(pnpPath)) { @@ -144,7 +147,7 @@ type GetPackageAccessibleBinariesOptions = { /** * Return the binaries that can be accessed by the specified package - * + * * @param locator The queried package * @param project The project owning the package */ @@ -161,43 +164,43 @@ export async function getPackageAccessibleBinaries(locator: Locator, {project}: const linkers = project.configuration.getLinkers(); const linkerOptions = {project, report: new StreamReport({ configuration, stdout })}; - + const binaries: Map = new Map(); - + const descriptors = [ ... pkg.dependencies.values(), ... pkg.peerDependencies.values(), ]; - + for (const descriptor of descriptors) { const resolution = project.storedResolutions.get(descriptor.descriptorHash); if (!resolution) continue; - + const pkg = project.storedPackages.get(resolution); if (!pkg) continue; - + const linker = linkers.find(linker => linker.supportsPackage(pkg, linkerOptions)); if (!linker) continue; - + const packageLocation = await linker.findPackageLocation(pkg, linkerOptions); const packageFs = new CwdFS(packageLocation, {baseFs: zipOpenFs}); const manifest = await Manifest.find(`.`, {baseFs: packageFs}); - + for (const [binName, file] of manifest.bin.entries()) { binaries.set(binName, [pkg, posix.resolve(packageLocation, file)]); } } - + return binaries; }); } /** * Return the binaries that can be accessed by the specified workspace - * + * * @param workspace The queried workspace */ @@ -215,11 +218,11 @@ type ExecutePackageAccessibleBinaryOptions = { /** * Execute a binary from the specified package. - * + * * Note that "binary" in this sense means "a Javascript file". Actual native * binaries cannot be executed this way, because we use Node in order to * transparently read from the archives. - * + * * @param locator The queried package * @param binaryName The name of the binary file to execute * @param args The arguments to pass to the file @@ -254,7 +257,7 @@ type ExecuteWorkspaceAccessibleBinaryOptions = { /** * Execute a binary from the specified workspace - * + * * @param workspace The queried package * @param binaryName The name of the binary file to execute * @param args The arguments to pass to the file diff --git a/packages/berry-shell/sources/index.ts b/packages/berry-shell/sources/index.ts index 361fd4765eb9..7f3ddd7d0182 100644 --- a/packages/berry-shell/sources/index.ts +++ b/packages/berry-shell/sources/index.ts @@ -1,4 +1,4 @@ -import {xfs, NodeFS} from '@berry/fslib'; +import {xfs, NodeFS} from '@berry/fslib'; import {CommandSegment, CommandChain, CommandLine, ShellLine, parseShell} from '@berry/parsers'; import {spawn} from 'child_process'; import {delimiter, posix} from 'path'; @@ -133,13 +133,10 @@ const BUILTINS = new Map([ for (const key of Object.keys(state.environment)) normalizedEnv[key.toUpperCase()] = state.environment[key] as string; - // We must make sure the PATH is properly converted into the - // system-specific format - if (normalizedEnv.PATH && posix.delimiter !== delimiter) - normalizedEnv.PATH = normalizedEnv.PATH.replace(new RegExp(posix.delimiter, `g`), delimiter); const subprocess = spawn(ident, rest, { cwd: NodeFS.fromPortablePath(state.cwd), + shell: process.platform === `win32`, // Needed to execute .cmd files env: normalizedEnv, stdio, }); @@ -566,11 +563,8 @@ export async function execute(command: string, args: Array = [], { if (paths.length > 0) normalizedEnv.PATH = normalizedEnv.PATH - ? `${paths.join(posix.delimiter)}${posix.delimiter}${env.PATH}` - : `${paths.join(posix.delimiter)}`; - - if (normalizedEnv.PATH && delimiter !== posix.delimiter) - normalizedEnv.PATH = normalizedEnv.PATH.replace(new RegExp(delimiter, `g`), posix.delimiter); + ? `${paths.join(delimiter)}${delimiter}${env.PATH}` + : `${paths.join(delimiter)}`; const normalizedBuiltins = new Map(BUILTINS); for (const [key, action] of Object.entries(builtins))