Skip to content

Commit

Permalink
Skips setting node_option when useless (yarnpkg#800)
Browse files Browse the repository at this point in the history
* Skips setting node_option when useless

* Adds versions
  • Loading branch information
arcanis authored Jan 27, 2020
1 parent a11b52a commit c77555f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 39 deletions.
6 changes: 1 addition & 5 deletions .vscode/pnpify/eslint/bin/eslint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

Expand All @@ -11,9 +11,5 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
// Setup the environment to be able to require eslint/bin/eslint.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real eslint/bin/eslint.js your application uses
module.exports = absRequire(`eslint/bin/eslint.js`);
6 changes: 1 addition & 5 deletions .vscode/pnpify/eslint/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

Expand All @@ -11,9 +11,5 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
// Setup the environment to be able to require eslint/lib/api.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real eslint/lib/api.js your application uses
module.exports = absRequire(`eslint/lib/api.js`);
6 changes: 1 addition & 5 deletions .vscode/pnpify/typescript/bin/tsc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

Expand All @@ -11,9 +11,5 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
// Setup the environment to be able to require typescript/bin/tsc
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/bin/tsc your application uses
module.exports = absRequire(`typescript/bin/tsc`);
6 changes: 1 addition & 5 deletions .vscode/pnpify/typescript/bin/tsserver
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

Expand All @@ -11,9 +11,5 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
// Setup the environment to be able to require typescript/bin/tsserver
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/bin/tsserver your application uses
module.exports = absRequire(`typescript/bin/tsserver`);
6 changes: 1 addition & 5 deletions .vscode/pnpify/typescript/lib/tsc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

Expand All @@ -11,9 +11,5 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
// Setup the environment to be able to require typescript/lib/tsc.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/lib/tsc.js your application uses
module.exports = absRequire(`typescript/lib/tsc.js`);
6 changes: 1 addition & 5 deletions .vscode/pnpify/typescript/lib/tsserver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const {createRequire, createRequireFromPath} = require(`module`);
const {dirname, resolve} = require(`path`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.js";

Expand All @@ -11,9 +11,5 @@ const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
// Setup the environment to be able to require typescript/lib/tsserver.js
require(absPnpApiPath).setup();

// Prepare the environment (to be ready in case of child_process.spawn etc)
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || ``;
process.env.NODE_OPTIONS += ` -r ${absPnpApiPath}`;

// Defer to the real typescript/lib/tsserver.js your application uses
module.exports = absRequire(`typescript/lib/tsserver.js`);
9 changes: 9 additions & 0 deletions .yarn/versions/a8210a0e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
releases:
"@yarnpkg/pnpify": prerelease

declined:
- "@yarnpkg/plugin-node-modules"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/cli"
- "@yarnpkg/pnp"
27 changes: 18 additions & 9 deletions packages/yarnpkg-pnpify/sources/generateSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import CJSON from 'comment-json';

import {dynamicRequire} from './dynamicRequire';

const TEMPLATE = (relPnpApiPath: PortablePath, module: string, {usePnpify}: {usePnpify: boolean}) => [
type TemplateOptions = {
setupEnv?: boolean,
usePnpify?: boolean,
};

const TEMPLATE = (relPnpApiPath: PortablePath, module: string, {setupEnv = false, usePnpify = false}: TemplateOptions) => [
`#!/usr/bin/env node\n`,
`\n`,
`const {createRequire, createRequireFromPath} = require(\`module\`);\n`,
Expand All @@ -16,10 +21,14 @@ const TEMPLATE = (relPnpApiPath: PortablePath, module: string, {usePnpify}: {use
`\n`,
`// Setup the environment to be able to require ${module}\n`,
`require(absPnpApiPath).setup();\n`,
`\n`,
`// Prepare the environment (to be ready in case of child_process.spawn etc)\n`,
`process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || \`\`;\n`,
`process.env.NODE_OPTIONS += \` -r \${absPnpApiPath}\`;\n`,
...(setupEnv || usePnpify ? [
`\n`,
`// Prepare the environment (to be ready in case of child_process.spawn etc)\n`,
] : []),
...(setupEnv ? [
`process.env.NODE_OPTIONS = process.env.NODE_OPTIONS || \`\`;\n`,
`process.env.NODE_OPTIONS += \` -r \${absPnpApiPath}\`;\n`,
] : []),
...(usePnpify ? [
`process.env.NODE_OPTIONS += \` -r \${pnpifyResolution}\`;\n`,
`\n`,
Expand Down Expand Up @@ -71,19 +80,19 @@ class Wrapper {
}, null, 2));
}

async writeBinary(relPackagePath: PortablePath) {
const absPackagePath = await this.writeFile(relPackagePath);
async writeBinary(relPackagePath: PortablePath, options: TemplateOptions = {}) {
const absPackagePath = await this.writeFile(relPackagePath, options);

await xfs.chmodPromise(absPackagePath, 0o755);
}

async writeFile(relPackagePath: PortablePath) {
async writeFile(relPackagePath: PortablePath, options: TemplateOptions = {}) {
const absWrapperPath = ppath.join(this.target, this.name, relPackagePath);
const relPnpApiPath = ppath.relative(ppath.dirname(absWrapperPath), ppath.join(this.projectRoot, `.pnp.js` as Filename));
const relProjectPath = ppath.relative(this.projectRoot, absWrapperPath);

await xfs.mkdirpPromise(ppath.dirname(absWrapperPath));
await xfs.writeFilePromise(absWrapperPath, TEMPLATE(relPnpApiPath, ppath.join(this.name, relPackagePath), {usePnpify: false}));
await xfs.writeFilePromise(absWrapperPath, TEMPLATE(relPnpApiPath, ppath.join(this.name, relPackagePath), options));

this.paths.set(relPackagePath, relProjectPath);

Expand Down

0 comments on commit c77555f

Please sign in to comment.