Skip to content

Commit b6dbb68

Browse files
Embraser01arcanis
authored andcommitted
Adds support for Windows paths (#33)
* Base work for portable path * Add conversion where needed (still missing some!) * Got it to work on Windows! * Convert to portable path when calling 'yarn <path> install' * Update config.ts * Use posix where possible * Use xfs in json-proxy instead of native fs * Fix berry json proxy dependencies * Handle more special cases (globby, pnp), activate Windows Pipeline * Fix PATH env variable when spawn process * Fix azure yaml * Fixes plugin loading * Updates the checked-in build * Fixes yarn-path execution * Debug: Adds logging to findZip * Revert "Debug: Adds logging to findZip" This reverts commit e616b6b. * Enforces symlinks on Windows * Fixes the cmd scripts * Adds a retry for EBUSY and ENOTEMPTY * Fixes process spawning on win32 * More portable path, prevent translating to portable path if already one * Some cleanup for PnP hook on Windows * Use only portable path in Native resolution * Moves the portable path conversion in dedicated wrappers * Makes fakeFs a parameter to instantiate a PnP API * Updates the PnP hook * Fixes accidental infinite loop * Updates the checked-in PnP hook * Fixes how the PnP linker interacts with the PnP API on Windows * Implements a fs layer to convert paths before they reach zipopenfs * Adds a few extra conversions * Updates the checked-in build
1 parent 1795e83 commit b6dbb68

File tree

36 files changed

+4320
-3460
lines changed

36 files changed

+4320
-3460
lines changed

.pnp.js

Lines changed: 600 additions & 356 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure-pipelines.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
jobs:
22

3-
# - job: Windows
4-
# pool: 'Hosted VS2017'
3+
- job: Windows
4+
pool:
5+
vmImage: 'vs2017-win2016'
56

6-
# variables:
7-
# os_name: Windows
7+
variables:
8+
os_name: Windows
89

9-
# strategy:
10-
# matrix:
11-
# node_8_x:
12-
# node_version: 8.x
13-
# node_10_x:
14-
# node_version: 10.x
10+
strategy:
11+
matrix:
12+
node_8_x:
13+
node_version: 8.x
14+
node_10_x:
15+
node_version: 10.x
1516

16-
# steps:
17-
# - template: scripts/azure-run-tests.yml
17+
steps:
18+
- bash: |
19+
git config core.symlinks true
20+
git reset --hard
21+
- template: scripts/azure-run-tests.yml
1822

1923
- job: Linux
2024
pool:

packages/acceptance-tests/pkg-tests-specs/sources/pnp.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe(`Plug'n'Play`, () => {
6868
},
6969
},
7070
async ({path, run, source}) => {
71+
console.log(path);
7172
await run(`install`);
7273

7374
await expect(

packages/berry-cli/bin/berry.js

Lines changed: 3089 additions & 2821 deletions
Large diffs are not rendered by default.

packages/berry-cli/sources/cli.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Configuration} from '@berry/core';
2-
import {xfs} from '@berry/fslib';
2+
import {xfs, NodeFS} from '@berry/fslib';
33
import {UsageError, Concierge} from '@manaflair/concierge';
44
import {execFileSync} from 'child_process';
55
import Joi from 'joi';
@@ -13,16 +13,18 @@ concierge.topLevel(`[--cwd PATH]`).validate(Joi.object().unknown().keys({
1313
}));
1414

1515
function runBinary(path: string) {
16-
if (path.endsWith(`.js`)) {
17-
execFileSync(process.execPath, [path, ...process.argv.slice(2)], {
16+
const physicalPath = NodeFS.fromPortablePath(path);
17+
18+
if (physicalPath) {
19+
execFileSync(process.execPath, [physicalPath, ...process.argv.slice(2)], {
1820
stdio: `inherit`,
1921
env: {
2022
... process.env,
2123
YARN_IGNORE_PATH: `1`,
2224
}
2325
});
2426
} else {
25-
execFileSync(path, process.argv.slice(2), {
27+
execFileSync(physicalPath, process.argv.slice(2), {
2628
stdio: `inherit`,
2729
env: {
2830
... process.env,
@@ -33,7 +35,7 @@ function runBinary(path: string) {
3335
}
3436

3537
async function run() {
36-
const configuration = await Configuration.find(process.cwd(), pluginConfiguration);
38+
const configuration = await Configuration.find(NodeFS.toPortablePath(process.cwd()), pluginConfiguration);
3739

3840
const yarnPath = configuration.get(`yarnPath`);
3941
const ignorePath = configuration.get(`ignorePath`);
@@ -54,7 +56,9 @@ async function run() {
5456
for (const command of plugin.commands || [])
5557
command(concierge, pluginConfiguration);
5658

57-
concierge.runExit(`yarn`, process.argv.slice(2));
59+
concierge.runExit(`yarn`, process.argv.slice(2), {
60+
cwd: NodeFS.toPortablePath(process.cwd())
61+
});
5862
}
5963
}
6064

packages/berry-core/sources/Cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {NodeFS, ZipFS, xfs} from '@berry/fslib';
22
import {lock, unlock} from 'lockfile';
3-
import posix from 'path';
3+
import {posix} from 'path';
44
import {promisify} from 'util';
55

66
import {Configuration} from './Configuration';
@@ -59,7 +59,7 @@ export class Cache {
5959

6060
if (expectedChecksum !== null && actualChecksum !== expectedChecksum)
6161
throw new ReportError(MessageName.CACHE_CHECKSUM_MISMATCH, `${structUtils.prettyLocator(this.configuration, locator)} doesn't resolve to an archive that matches the expected checksum`);
62-
62+
6363
return actualChecksum;
6464
};
6565

@@ -115,7 +115,7 @@ export class Cache {
115115
}
116116

117117
async writeFileIntoCache<T>(file: string, generator: (file: string) => Promise<T>) {
118-
const lock = `${file}.lock`;
118+
const lock = NodeFS.fromPortablePath(`${file}.lock`);
119119

120120
try {
121121
await lockP(lock);

packages/berry-core/sources/Configuration.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {xfs} from '@berry/fslib';
1+
import {xfs, NodeFS} from '@berry/fslib';
22
import {parseSyml, stringifySyml} from '@berry/parsers';
33
import {UsageError} from '@manaflair/concierge';
44
import chalk from 'chalk';
55
import {homedir} from 'os';
6-
import {posix} from 'path';
6+
import {posix, win32} from 'path';
77
import supportsColor from 'supports-color';
88

99
import {MultiFetcher} from './MultiFetcher';
@@ -234,7 +234,7 @@ function parseValue(value: unknown, type: SettingsType, folder: string) {
234234
throw new Error(`Expected value to be a string`);
235235

236236
if (type === SettingsType.ABSOLUTE_PATH) {
237-
return posix.resolve(folder, value);
237+
return posix.resolve(folder, NodeFS.toPortablePath(value));
238238
} else if (type === SettingsType.LOCATOR_LOOSE) {
239239
return structUtils.parseLocator(value, false);
240240
} else if (type === SettingsType.LOCATOR) {
@@ -246,7 +246,8 @@ function parseValue(value: unknown, type: SettingsType, folder: string) {
246246

247247
function getDefaultGlobalFolder() {
248248
if (process.platform === `win32`) {
249-
return posix.resolve(process.env.LOCALAPPDATA || posix.join(homedir(), 'AppData', 'Local'));
249+
const folder = NodeFS.toPortablePath(process.env.LOCALAPPDATA || win32.join(homedir(), 'AppData', 'Local'));
250+
return posix.resolve(folder);
250251
} else if (process.env.XDG_DATA_HOME) {
251252
return posix.resolve(process.env.XDG_DATA_HOME, 'yarn/modern');
252253
} else {
@@ -359,8 +360,9 @@ export class Configuration {
359360
if (!Array.isArray(data.plugins))
360361
continue;
361362

362-
for (const pluginPath of data.plugins) {
363-
const {factory, name} = nodeUtils.dynamicRequire(posix.resolve(cwd, pluginPath));
363+
for (const userProvidedPath of data.plugins) {
364+
const pluginPath = posix.resolve(cwd, NodeFS.toPortablePath(userProvidedPath));
365+
const {factory, name} = nodeUtils.dynamicRequire(NodeFS.fromPortablePath(pluginPath));
364366

365367
// Prevent plugin redefinition so that the ones declared deeper in the
366368
// filesystem always have precedence over the ones below.

0 commit comments

Comments
 (0)