Skip to content

Commit

Permalink
Adds support for Windows paths (#33)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Embraser01 authored and arcanis committed Mar 26, 2019
1 parent 1795e83 commit b6dbb68
Show file tree
Hide file tree
Showing 36 changed files with 4,320 additions and 3,460 deletions.
956 changes: 600 additions & 356 deletions .pnp.js

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
jobs:

# - job: Windows
# pool: 'Hosted VS2017'
- job: Windows
pool:
vmImage: 'vs2017-win2016'

# variables:
# os_name: Windows
variables:
os_name: Windows

# strategy:
# matrix:
# node_8_x:
# node_version: 8.x
# node_10_x:
# node_version: 10.x
strategy:
matrix:
node_8_x:
node_version: 8.x
node_10_x:
node_version: 10.x

# steps:
# - template: scripts/azure-run-tests.yml
steps:
- bash: |
git config core.symlinks true
git reset --hard
- template: scripts/azure-run-tests.yml

- job: Linux
pool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe(`Plug'n'Play`, () => {
},
},
async ({path, run, source}) => {
console.log(path);
await run(`install`);

await expect(
Expand Down
5,910 changes: 3,089 additions & 2,821 deletions packages/berry-cli/bin/berry.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions packages/berry-cli/sources/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Configuration} from '@berry/core';
import {xfs} from '@berry/fslib';
import {xfs, NodeFS} from '@berry/fslib';
import {UsageError, Concierge} from '@manaflair/concierge';
import {execFileSync} from 'child_process';
import Joi from 'joi';
Expand All @@ -13,16 +13,18 @@ concierge.topLevel(`[--cwd PATH]`).validate(Joi.object().unknown().keys({
}));

function runBinary(path: string) {
if (path.endsWith(`.js`)) {
execFileSync(process.execPath, [path, ...process.argv.slice(2)], {
const physicalPath = NodeFS.fromPortablePath(path);

if (physicalPath) {
execFileSync(process.execPath, [physicalPath, ...process.argv.slice(2)], {
stdio: `inherit`,
env: {
... process.env,
YARN_IGNORE_PATH: `1`,
}
});
} else {
execFileSync(path, process.argv.slice(2), {
execFileSync(physicalPath, process.argv.slice(2), {
stdio: `inherit`,
env: {
... process.env,
Expand All @@ -33,7 +35,7 @@ function runBinary(path: string) {
}

async function run() {
const configuration = await Configuration.find(process.cwd(), pluginConfiguration);
const configuration = await Configuration.find(NodeFS.toPortablePath(process.cwd()), pluginConfiguration);

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

concierge.runExit(`yarn`, process.argv.slice(2));
concierge.runExit(`yarn`, process.argv.slice(2), {
cwd: NodeFS.toPortablePath(process.cwd())
});
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/berry-core/sources/Cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {NodeFS, ZipFS, xfs} from '@berry/fslib';
import {lock, unlock} from 'lockfile';
import posix from 'path';
import {posix} from 'path';
import {promisify} from 'util';

import {Configuration} from './Configuration';
Expand Down Expand Up @@ -59,7 +59,7 @@ export class Cache {

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

return actualChecksum;
};

Expand Down Expand Up @@ -115,7 +115,7 @@ export class Cache {
}

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

try {
await lockP(lock);
Expand Down
14 changes: 8 additions & 6 deletions packages/berry-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {xfs} from '@berry/fslib';
import {xfs, NodeFS} from '@berry/fslib';
import {parseSyml, stringifySyml} from '@berry/parsers';
import {UsageError} from '@manaflair/concierge';
import chalk from 'chalk';
import {homedir} from 'os';
import {posix} from 'path';
import {posix, win32} from 'path';
import supportsColor from 'supports-color';

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

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

function getDefaultGlobalFolder() {
if (process.platform === `win32`) {
return posix.resolve(process.env.LOCALAPPDATA || posix.join(homedir(), 'AppData', 'Local'));
const folder = NodeFS.toPortablePath(process.env.LOCALAPPDATA || win32.join(homedir(), 'AppData', 'Local'));
return posix.resolve(folder);
} else if (process.env.XDG_DATA_HOME) {
return posix.resolve(process.env.XDG_DATA_HOME, 'yarn/modern');
} else {
Expand Down Expand Up @@ -359,8 +360,9 @@ export class Configuration {
if (!Array.isArray(data.plugins))
continue;

for (const pluginPath of data.plugins) {
const {factory, name} = nodeUtils.dynamicRequire(posix.resolve(cwd, pluginPath));
for (const userProvidedPath of data.plugins) {
const pluginPath = posix.resolve(cwd, NodeFS.toPortablePath(userProvidedPath));
const {factory, name} = nodeUtils.dynamicRequire(NodeFS.fromPortablePath(pluginPath));

// Prevent plugin redefinition so that the ones declared deeper in the
// filesystem always have precedence over the ones below.
Expand Down
Loading

0 comments on commit b6dbb68

Please sign in to comment.