mirror of https://github.com/nodejs/corepack.git
build: migrate to esbuild (#229)
This commit is contained in:
parent
84e6e1d018
commit
15ceb832a3
|
|
@ -6,6 +6,9 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
YARN_ENABLE_GLOBAL_CACHE: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
chore:
|
chore:
|
||||||
name: "Testing chores"
|
name: "Testing chores"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
YARN_ENABLE_GLOBAL_CACHE: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-please:
|
release-please:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ on:
|
||||||
type: number
|
type: number
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
YARN_ENABLE_GLOBAL_CACHE: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-update-nock-files:
|
build-and-update-nock-files:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ import {Engine} from './sources/Engine';
|
||||||
import {SupportedPackageManagerSet} from './sources/types';
|
import {SupportedPackageManagerSet} from './sources/types';
|
||||||
|
|
||||||
function shouldGenerateShim(name: string) {
|
function shouldGenerateShim(name: string) {
|
||||||
return name !== `chunks`;
|
// No filtering needed at the moment
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const engine = new Engine();
|
const engine = new Engine();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
"babel-plugin-dynamic-import-node": "^2.3.3",
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
||||||
"clipanion": "^3.0.1",
|
"clipanion": "^3.0.1",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
|
"esbuild": "0.16.15",
|
||||||
"eslint": "^8.0.0",
|
"eslint": "^8.0.0",
|
||||||
"eslint-plugin-arca": "^0.15.0",
|
"eslint-plugin-arca": "^0.15.0",
|
||||||
"jest": "^29.0.0",
|
"jest": "^29.0.0",
|
||||||
|
|
@ -40,16 +41,14 @@
|
||||||
"semver": "^7.1.3",
|
"semver": "^7.1.3",
|
||||||
"supports-color": "^9.0.0",
|
"supports-color": "^9.0.0",
|
||||||
"tar": "^6.0.1",
|
"tar": "^6.0.1",
|
||||||
"ts-loader": "^9.0.0",
|
|
||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.0.0",
|
||||||
"typescript": "^4.3.2",
|
"typescript": "^4.3.2",
|
||||||
"v8-compile-cache": "^2.3.0",
|
"v8-compile-cache": "^2.3.0",
|
||||||
"webpack": "^5.38.1",
|
|
||||||
"webpack-cli": "^4.0.0",
|
|
||||||
"which": "^2.0.2"
|
"which": "^2.0.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf dist shims && webpack && ts-node ./mkshims.ts",
|
"build": "rm -rf dist shims && run build:bundle && ts-node ./mkshims.ts",
|
||||||
|
"build:bundle": "esbuild ./sources/_entryPoint.ts --bundle --platform=node --target=node14.14.0 --external:corepack --outfile='./dist/corepack.js' --resolve-extensions='.ts,.mjs,.js'",
|
||||||
"corepack": "ts-node ./sources/_entryPoint.ts",
|
"corepack": "ts-node ./sources/_entryPoint.ts",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"prepack": "yarn build",
|
"prepack": "yarn build",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
import {runMain} from './main';
|
import {runMain} from './main';
|
||||||
|
|
||||||
// Used by the generated shims
|
// Used by the generated shims
|
||||||
export {runMain};
|
export {runMain};
|
||||||
|
|
||||||
// Using `eval` to be sure that Webpack doesn't transform it
|
if (process.mainModule === module)
|
||||||
if (process.mainModule === eval(`module`))
|
|
||||||
runMain(process.argv.slice(2));
|
runMain(process.argv.slice(2));
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import path from 'p
|
||||||
import which from 'which';
|
import which from 'which';
|
||||||
|
|
||||||
import {Context} from '../main';
|
import {Context} from '../main';
|
||||||
import * as nodeUtils from '../nodeUtils';
|
|
||||||
import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types';
|
import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types';
|
||||||
|
|
||||||
export class EnableCommand extends Command<Context> {
|
export class EnableCommand extends Command<Context> {
|
||||||
|
|
@ -51,8 +50,7 @@ export class EnableCommand extends Command<Context> {
|
||||||
// install directory is within a symlink
|
// install directory is within a symlink
|
||||||
installDirectory = fs.realpathSync(installDirectory);
|
installDirectory = fs.realpathSync(installDirectory);
|
||||||
|
|
||||||
// We use `eval` so that Webpack doesn't statically transform it.
|
const manifestPath = require.resolve(`corepack/package.json`);
|
||||||
const manifestPath = nodeUtils.dynamicRequire.resolve(`corepack/package.json`);
|
|
||||||
|
|
||||||
const distFolder = path.join(path.dirname(manifestPath), `dist`);
|
const distFolder = path.join(path.dirname(manifestPath), `dist`);
|
||||||
if (!fs.existsSync(distFolder))
|
if (!fs.existsSync(distFolder))
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export class HydrateCommand extends Command<Context> {
|
||||||
const archiveEntries = new Map<string, Set<string>>();
|
const archiveEntries = new Map<string, Set<string>>();
|
||||||
let hasShortEntries = false;
|
let hasShortEntries = false;
|
||||||
|
|
||||||
const {default: tar} = await import(/* webpackMode: 'eager' */ `tar`);
|
const {default: tar} = await import(`tar`);
|
||||||
|
|
||||||
await tar.t({file: fileName, onentry: entry => {
|
await tar.t({file: fileName, onentry: entry => {
|
||||||
const segments = entry.header.path.split(/\//g);
|
const segments = entry.header.path.split(/\//g);
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ export class PrepareCommand extends Command<Context> {
|
||||||
if (!this.json)
|
if (!this.json)
|
||||||
this.context.stdout.write(`Packing the selected tools in ${path.basename(outputPath)}...\n`);
|
this.context.stdout.write(`Packing the selected tools in ${path.basename(outputPath)}...\n`);
|
||||||
|
|
||||||
const {default: tar} = await import(/* webpackMode: 'eager' */ `tar`);
|
const {default: tar} = await import(`tar`);
|
||||||
// Recreate the folder in case it was deleted somewhere else:
|
// Recreate the folder in case it was deleted somewhere else:
|
||||||
await mkdir(baseInstallFolder, {recursive: true});
|
await mkdir(baseInstallFolder, {recursive: true});
|
||||||
await tar.c({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => {
|
await tar.c({gzip: true, cwd: baseInstallFolder, file: path.resolve(outputPath)}, installLocations.map(location => {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ export async function findInstalledVersion(installTarget: string, descriptor: De
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installVersion(installTarget: string, locator: Locator, {spec}: {spec: PackageManagerSpec}) {
|
export async function installVersion(installTarget: string, locator: Locator, {spec}: {spec: PackageManagerSpec}) {
|
||||||
const {default: tar} = await import(/* webpackMode: 'eager' */ `tar`);
|
const {default: tar} = await import(`tar`);
|
||||||
const {version, build} = semver.parse(locator.reference)!;
|
const {version, build} = semver.parse(locator.reference)!;
|
||||||
|
|
||||||
const installFolder = path.join(installTarget, locator.name, version);
|
const installFolder = path.join(installTarget, locator.name, version);
|
||||||
|
|
@ -194,7 +194,7 @@ export async function runVersion(installSpec: { location: string, spec: PackageM
|
||||||
// - Yarn uses process.argv[1] to determine its own path: https://github.com/yarnpkg/berry/blob/0da258120fc266b06f42aed67e4227e81a2a900f/packages/yarnpkg-cli/sources/main.ts#L80
|
// - Yarn uses process.argv[1] to determine its own path: https://github.com/yarnpkg/berry/blob/0da258120fc266b06f42aed67e4227e81a2a900f/packages/yarnpkg-cli/sources/main.ts#L80
|
||||||
// - pnpm uses `require.main == null` to determine its own version: https://github.com/pnpm/pnpm/blob/e2866dee92991e979b2b0e960ddf5a74f6845d90/packages/cli-meta/src/index.ts#L14
|
// - pnpm uses `require.main == null` to determine its own version: https://github.com/pnpm/pnpm/blob/e2866dee92991e979b2b0e960ddf5a74f6845d90/packages/cli-meta/src/index.ts#L14
|
||||||
|
|
||||||
process.env.COREPACK_ROOT = path.dirname(eval(`__dirname`));
|
process.env.COREPACK_ROOT = path.dirname(require.resolve(`corepack/package.json`));
|
||||||
|
|
||||||
process.argv = [
|
process.argv = [
|
||||||
process.execPath,
|
process.execPath,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import {BaseContext, Builtins, Cli, Command, Option, UsageError} from 'clipanion';
|
import {BaseContext, Builtins, Cli, Command, Option, UsageError} from 'clipanion';
|
||||||
|
|
||||||
|
import {version as corepackVersion} from '../package.json';
|
||||||
|
|
||||||
import {Engine} from './Engine';
|
import {Engine} from './Engine';
|
||||||
import {DisableCommand} from './commands/Disable';
|
import {DisableCommand} from './commands/Disable';
|
||||||
import {EnableCommand} from './commands/Enable';
|
import {EnableCommand} from './commands/Enable';
|
||||||
|
|
@ -87,8 +89,6 @@ async function executePackageManagerRequest({packageManager, binaryName, binaryV
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(argv: Array<string>) {
|
async function main(argv: Array<string>) {
|
||||||
const corepackVersion = require(`../package.json`).version;
|
|
||||||
|
|
||||||
// Because we load the binaries in the same process, we don't support custom contexts.
|
// Because we load the binaries in the same process, we don't support custom contexts.
|
||||||
const context = {
|
const context = {
|
||||||
...Cli.defaultContext,
|
...Cli.defaultContext,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
import Module from 'module';
|
import Module from 'module';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
declare const __non_webpack_require__: NodeRequire | undefined;
|
|
||||||
|
|
||||||
export const dynamicRequire: NodeRequire = typeof __non_webpack_require__ !== `undefined`
|
|
||||||
? __non_webpack_require__
|
|
||||||
: require;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a module as a main module, enabling the `require.main === module` pattern.
|
* Loads a module as a main module, enabling the `require.main === module` pattern.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
const webpack = require(`webpack`);
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mode: `production`,
|
|
||||||
devtool: false,
|
|
||||||
target: `node`,
|
|
||||||
entry: {
|
|
||||||
[`corepack`]: `./sources/_entryPoint.ts`,
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
libraryTarget: `commonjs`,
|
|
||||||
chunkFilename: `chunks/[name].cjs`,
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: [`.ts`, `.js`],
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
noParse: /v8-compile-cache/,
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.ts$/,
|
|
||||||
loader: `ts-loader`,
|
|
||||||
options: {
|
|
||||||
compilerOptions: {
|
|
||||||
module: `ES2020`,
|
|
||||||
noEmit: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
stats: {
|
|
||||||
assetsSort: `!size`,
|
|
||||||
},
|
|
||||||
optimization: {
|
|
||||||
minimize: false,
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new webpack.BannerPlugin({
|
|
||||||
entryOnly: true,
|
|
||||||
banner: `#!/usr/bin/env node\n/* eslint-disable */`,
|
|
||||||
raw: true,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue