Skip to content

Commit

Permalink
Bundle CLI for NPM package (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Nov 14, 2022
1 parent a7f1799 commit 8d0b9ec
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 28 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/dev-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ jobs:
node-version: '16.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@microsoft'
- run: yarn
- run: yarn lint
- run: yarn package
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Type-Check
run: yarn type-check
- name: Lint
run: yarn lint
- name: Package
run: yarn package
- name: TGZ name
run: |
VERSION=$(jq -r '.version' < package.json)
Expand Down Expand Up @@ -62,9 +67,9 @@ jobs:
registry-url: 'https://npm.pkg.github.com'
scope: '@microsoft'
- name: Install Dependencies
run: yarn
- name: Compile
run: yarn compile
run: yarn install --frozen-lockfile
- name: Type-Check
run: yarn type-check
- name: Package
run: yarn package
- name: Run Tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
built
node_modules
logs
*.log
Expand Down
21 changes: 15 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@
}
},
"tasks": [
{
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"label": "Build Dev Containers CLI",
"detail": "Runs watch and type-check-watch",
"dependsOn": [
"npm: type-check-watch",
"npm: watch"
]
},
{
"type": "npm",
"script": "watch",
"script": "type-check-watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"label": "Build Dev Containers CLI",
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
},
"group": "build"
},
{
"type": "npm",
Expand Down
22 changes: 20 additions & 2 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ const watch = process.argv.indexOf('--watch') !== -1;
loader: 'js',
};
});
build.onLoad({ filter: /node_modules[\/\\]vm2[\/\\]lib[\/\\]vm.js$/ }, async (args) => {
const text = await fs.promises.readFile(args.path, 'utf8');
const regex = /fs\.readFileSync\(`\$\{__dirname\}\/([^`]+)`, 'utf8'\)/g;
const files = await [...new Set(text.matchAll(regex))]
.reduce(async (prevP, m) => {
const text = (await fs.promises.readFile(path.join(path.dirname(args.path), m[1]), 'utf8'));
const prev = await prevP;
prev[m[1]] = text;
return prev;
}, Promise.resolve({}));
const contents = text.replace(regex, (_sub, file) => {
return `\`${files[file].replace(/[`$]/g, '\\$&')}\``;
});
return {
contents,
loader: 'js',
};
});
},
};

Expand All @@ -39,8 +57,8 @@ const watch = process.argv.indexOf('--watch') !== -1;
minify,
watch,
platform: 'node',
target: 'node12.18.3',
external: ['vscode', 'vscode-dev-containers'],
target: 'node14.14.0',
external: ['vscode-dev-containers'],
mainFields: ['module', 'main'],
outdir: 'dist',
plugins: [plugin],
Expand Down
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@
"node": ">=14.14.0"
},
"scripts": {
"compile": "npm-run-all clean definitions tsc-b",
"compile": "npm-run-all clean-dist definitions compile-dev",
"watch": "npm-run-all clean-dist definitions compile-watch",
"package": "npm-run-all clean-dist definitions compile-prod npm-pack",
"type-check": "npm-run-all clean-built tsc-b",
"type-check-watch": "npm-run-all clean-built tsc-b-w",
"compile-prod": "node esbuild.js --production",
"compile-dev": "node esbuild.js",
"compile-watch": "node esbuild.js --watch",
"tsc-b": "tsc -b",
"watch": "npm-run-all clean definitions tsc-b-w",
"tsc-b-w": "tsc -b -w",
"precommit": "node build/hygiene.js",
"definitions": "npm-run-all definitions-clean definitions-copy",
"lint": "eslint -c .eslintrc.js --rulesdir ./build/eslint --max-warnings 0 --ext .ts ./src",
"definitions-clean": "rimraf dist/node_modules/vscode-dev-containers",
"definitions-copy": "copyfiles --all \"node_modules/vscode-dev-containers/**/*\" dist",
"package": "npm-run-all compile npm-pack",
"bundle": "npm-run-all clean definitions esbuild npm-pack",
"esbuild": "node esbuild.js --production",
"npm-pack": "npm pack",
"clean": "rimraf dist",
"clean": "npm-run-all clean-dist clean-built",
"clean-dist": "rimraf dist",
"clean-built": "rimraf built",
"test": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit src/test/*.test.ts",
"test-matrix": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit",
"test-container-features": "env TS_NODE_PROJECT=src/test/tsconfig.json mocha -r ts-node/register --exit src/test/container-features/*.test.ts",
Expand All @@ -43,7 +48,8 @@
"README.md",
"ThirdPartyNotices.txt",
"devcontainer.js",
"dist",
"dist/spec-node/devContainersSpecCLI.js",
"dist/node_modules/vscode-dev-containers",
"package.json",
"scripts/updateUID.Dockerfile"
],
Expand Down Expand Up @@ -78,15 +84,12 @@
"typescript": "^4.5.5",
"typescript-formatter": "^7.2.2",
"vinyl": "^2.2.1",
"vinyl-fs": "^3.0.3"
},
"dependencies": {
"vinyl-fs": "^3.0.3",
"chalk": "^4",
"follow-redirects": "^1.14.8",
"js-yaml": "^4.1.0",
"jsonc-parser": "^3.0.0",
"ncp": "^2.0.0",
"node-pty": "^0.10.1",
"proxy-agent": "^5.0.0",
"pull-stream": "^3.6.14",
"recursive-readdir": "^2.2.2",
Expand All @@ -97,5 +100,8 @@
"vscode-dev-containers": "https://github.com/microsoft/vscode-dev-containers/releases/download/v0.245.2/vscode-dev-containers-0.245.2.tgz",
"vscode-uri": "^3.0.3",
"yargs": "~17.0.1"
},
"dependencies": {
"node-pty": "^0.10.1"
}
}
2 changes: 1 addition & 1 deletion src/test/cli.exec.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function describeTests1({ text, options }: BuildKitOption) {
export function describeTests2({ text, options }: BuildKitOption) {

describe('Dev Containers CLI', function () {
this.timeout('180s');
this.timeout('240s');

const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp'));
const cli = `npx --prefix ${tmp} devcontainer`;
Expand Down
2 changes: 1 addition & 1 deletion src/test/dockerUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import assert from 'assert';
export const output = makeLog(createPlainLog(text => process.stdout.write(text), () => LogLevel.Trace));

describe('Docker utils', function () {
this.timeout(10 * 1000);
this.timeout(20 * 1000);

it('inspect image in docker.io', async () => {
const imageName = 'docker.io/library/ubuntu:latest';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "./src",
"outDir": "./dist",
"outDir": "./built",
"target": "es2019",
"module": "commonjs",
"esModuleInterop": true,
Expand Down

0 comments on commit 8d0b9ec

Please sign in to comment.