Skip to content

Commit

Permalink
Uses js-yaml for parsing (#183)
Browse files Browse the repository at this point in the history
* Adds js-yaml

* Optimizes a bit the lockfile parsing

* Supports more cases

* Supports more cases

* Branches the parsing depending on the v1 tag

* Updates the npm tests

* Fixes more tests

* More tests fixed

* Other tests + documentation
  • Loading branch information
arcanis committed May 24, 2019
1 parent b937035 commit d403efb
Show file tree
Hide file tree
Showing 20 changed files with 541 additions and 447 deletions.
4 changes: 4 additions & 0 deletions .pnp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions .yarnrc
@@ -1,12 +1,16 @@
## General settings

init-scope: berry

npm-publish-access: public

yarn-path: scripts/run-yarn.js

## List of plugins enabled in the current repository

plugins:
- scripts/plugin-exec.js
- scripts/plugin-stage.js
- scripts/plugin-typescript.js
- scripts/plugin-version.js
- scripts/plugin-workspace-tools.js

yarn-path: ./scripts/run-yarn.js
18 changes: 9 additions & 9 deletions packages/acceptance-tests/pkg-tests-specs/sources/auth.test.js
Expand Up @@ -43,7 +43,7 @@ describe(`Auth tests`, () => {
dependencies: {[`no-deps`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAlwaysAuth true\n`);
await writeFile(`${path}/.yarnrc`, `npmAlwaysAuth: true\n`);

await expect(run(`install`)).rejects.toThrowError(/No authentication configured for request/);
},
Expand All @@ -57,7 +57,7 @@ describe(`Auth tests`, () => {
dependencies: {[`private-package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthToken "${AUTH_TOKEN}"\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthToken: "${AUTH_TOKEN}"\n`);

// Rejected by 401 error from registry so no validation on the error message
await expect(run(`install`)).rejects.toThrow();
Expand All @@ -72,7 +72,7 @@ describe(`Auth tests`, () => {
dependencies: {[`@private/package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthToken "${AUTH_TOKEN}"\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthToken: "${AUTH_TOKEN}"\n`);

await run(`install`);

Expand All @@ -91,7 +91,7 @@ describe(`Auth tests`, () => {
dependencies: {[`private-package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthToken "${AUTH_TOKEN}"\nnpmAlwaysAuth true\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthToken: "${AUTH_TOKEN}"\nnpmAlwaysAuth: true\n`);

await run(`install`);

Expand All @@ -110,7 +110,7 @@ describe(`Auth tests`, () => {
dependencies: {[`private-package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthIdent "${AUTH_IDENT}"\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthIdent: "${AUTH_IDENT}"\n`);

// Rejected by 401 error from registry so no validation on the error message
await expect(run(`install`)).rejects.toThrow();
Expand All @@ -125,7 +125,7 @@ describe(`Auth tests`, () => {
dependencies: {[`@private/package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthIdent "${AUTH_IDENT}"\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthIdent: "${AUTH_IDENT}"\n`);

await run(`install`);

Expand All @@ -144,7 +144,7 @@ describe(`Auth tests`, () => {
dependencies: {[`private-package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthIdent "${AUTH_IDENT}"\nnpmAlwaysAuth true\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthIdent: "${AUTH_IDENT}"\nnpmAlwaysAuth: true\n`);

await run(`install`);

Expand All @@ -163,7 +163,7 @@ describe(`Auth tests`, () => {
dependencies: {[`private-package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthToken "${INVALID_AUTH_TOKEN}"\nnpmAlwaysAuth true\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthToken: "${INVALID_AUTH_TOKEN}"\nnpmAlwaysAuth: true\n`);

await expect(run(`install`)).rejects.toThrow();
},
Expand All @@ -177,7 +177,7 @@ describe(`Auth tests`, () => {
dependencies: {[`private-package`]: `1.0.0`},
},
async ({path, run, source}) => {
await writeFile(`${path}/.yarnrc`, `npmAuthIdent "${INVALID_AUTH_IDENT}"\nnpmAlwaysAuth true\n`);
await writeFile(`${path}/.yarnrc`, `npmAuthIdent: "${INVALID_AUTH_IDENT}"\nnpmAlwaysAuth: true\n`);

await expect(run(`install`)).rejects.toThrow();
},
Expand Down
Expand Up @@ -14,22 +14,22 @@ const environments = {
// Nothing to do
},
[`folder with rcfile`]: async ({path}) => {
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope berry-test\n`);
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope: berry-test\n`);
},
[`folder with rcfile without trailing newline`]: async ({path}) => {
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope berry-test`);
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope: berry-test`);
},
[`folder with rcfile and rc in parent`]: async ({path}) => {
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope berry-test\n`);
await writeFile(`${path}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope value-to-override\nlastUpdateCheck 1555784893958\n`);
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope: berry-test\n`);
await writeFile(`${path}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope: value-to-override\nlast-update-check: 1555784893958\n`);
},
[`folder with rcfile and rc in ancestor parent`]: async ({path}) => {
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope berry-test\n`);
await writeFile(`${path}/${RC_FILENAME}`, `init-scope value-to-override\nlastUpdateCheck 1555784893958\n`);
await writeFile(`${path}/${SUBFOLDER}/${SUBFOLDER}/${RC_FILENAME}`, `init-scope: berry-test\n`);
await writeFile(`${path}/${RC_FILENAME}`, `init-scope: value-to-override\nlast-update-check: 1555784893958\n`);
},
[`folder with rcfile and rc in home folder`]: async ({path, homePath}) => {
await writeFile(`${homePath}/${RC_FILENAME}`, `init-scope value-to-override\ndefaultLanguageName python\n`);
await writeFile(`${path}/${RC_FILENAME}`, `init-scope berry-test\nlastUpdateCheck 1555784893958\n`);
await writeFile(`${homePath}/${RC_FILENAME}`, `init-scope: value-to-override\ndefault-language-name: python\n`);
await writeFile(`${path}/${RC_FILENAME}`, `init-scope: berry-test\nlast-update-check: 1555784893958\n`);
},
};

Expand Down
@@ -0,0 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Commands npm login it should login a user with OTP setup 1`] = `
"npmAuthToken: 686159dc-64b3-413e-a244-2de2b8d1c36f
"
`;

exports[`Commands npm login it should login a user with OTP setup 2`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: Successfully logged in
YN0000: Done
",
}
`;

exports[`Commands npm login it should login a user with OTP to a specific scope 1`] = `
"init-scope: berry-test
npmScopes:
testScope:
npmAuthToken: 686159dc-64b3-413e-a244-2de2b8d1c36f
npmRegistryServer: \\"http://yarn.test.registry\\"
"
`;

exports[`Commands npm login it should login a user with OTP to a specific scope 2`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: Successfully logged in
YN0000: Done
",
}
`;

exports[`Commands npm login it should login a user with no OTP setup 1`] = `
"npmAuthToken: 316158de-64b3-413e-a244-2de2b8d1c80f
"
`;

exports[`Commands npm login it should login a user with no OTP setup 2`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: Successfully logged in
YN0000: Done
",
}
`;

exports[`Commands npm login it should login a user with no OTP setup to a specific scope 1`] = `
"init-scope: berry-test
npmScopes:
testScope:
npmAuthToken: 316158de-64b3-413e-a244-2de2b8d1c80f
npmRegistryServer: \\"http://yarn.test.registry\\"
"
`;

exports[`Commands npm login it should login a user with no OTP setup to a specific scope 2`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: Successfully logged in
YN0000: Done
",
}
`;
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Commands npm whoami it should print the npm registry username for a given scope 1`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: username
YN0000: Done
",
}
`;

exports[`Commands npm whoami it should print the npm registry username when config has a valid npmAuthIdent 1`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: username
YN0000: Done
",
}
`;

exports[`Commands npm whoami it should print the npm registry username when config has a valid npmAuthToken 1`] = `
Object {
"code": 0,
"stderr": "",
"stdout": "➤ YN0000: username
YN0000: Done
",
}
`;

0 comments on commit d403efb

Please sign in to comment.