From 2edb9bc9ca22ac478890af3e449727393b92097b Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 24 Mar 2022 14:13:18 -0700 Subject: [PATCH] Reapply parcel/watcher adoption Revert "Revert e7fffbf1c9169087f1098aedfe54c59c079fa3ac" This reverts commit 6786b0ad7dc638db71e4f219e9315ec5f2ae2298. Two changes: - Lazy import parcel/watcher - Add `@parcel/watcher` as a dev dep in extensions folder so that we pull in correct version for build os --- .../esbuild-notebook.js | 40 ++++++++----- .../esbuild-preview.js | 41 ++++++++----- extensions/markdown-math/esbuild.js | 57 +++++++++++-------- extensions/notebook-renderers/esbuild.js | 39 ++++++++----- extensions/package.json | 1 + extensions/simple-browser/esbuild-preview.js | 51 ++++++++++------- extensions/yarn.lock | 18 ++++++ 7 files changed, 161 insertions(+), 86 deletions(-) diff --git a/extensions/markdown-language-features/esbuild-notebook.js b/extensions/markdown-language-features/esbuild-notebook.js index bd5a325438d..fb32a3e986e 100644 --- a/extensions/markdown-language-features/esbuild-notebook.js +++ b/extensions/markdown-language-features/esbuild-notebook.js @@ -2,6 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +// @ts-check const path = require('path'); const esbuild = require('esbuild'); @@ -15,19 +16,30 @@ if (outputRootIndex >= 0) { outputRoot = args[outputRootIndex + 1]; } +const srcDir = path.join(__dirname, 'notebook'); const outDir = path.join(outputRoot, 'notebook-out'); -esbuild.build({ - entryPoints: [ - path.join(__dirname, 'notebook', 'index.ts'), - ], - bundle: true, - minify: true, - sourcemap: false, - format: 'esm', - outdir: outDir, - platform: 'browser', - target: ['es2020'], - watch: isWatch, - incremental: isWatch, -}).catch(() => process.exit(1)); +function build() { + return esbuild.build({ + entryPoints: [ + path.join(__dirname, 'notebook', 'index.ts'), + ], + bundle: true, + minify: true, + sourcemap: false, + format: 'esm', + outdir: outDir, + platform: 'browser', + target: ['es2020'], + }); +} + + +build().catch(() => process.exit(1)); + +if (isWatch) { + const watcher = require('@parcel/watcher'); + watcher.subscribe(srcDir, () => { + return build(); + }); +} diff --git a/extensions/markdown-language-features/esbuild-preview.js b/extensions/markdown-language-features/esbuild-preview.js index 727353c6e44..d6af78d016e 100644 --- a/extensions/markdown-language-features/esbuild-preview.js +++ b/extensions/markdown-language-features/esbuild-preview.js @@ -2,6 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +// @ts-check const path = require('path'); const esbuild = require('esbuild'); @@ -15,20 +16,30 @@ if (outputRootIndex >= 0) { outputRoot = args[outputRootIndex + 1]; } +const srcDir = path.join(__dirname, 'preview-src'); const outDir = path.join(outputRoot, 'media'); -esbuild.build({ - entryPoints: [ - path.join(__dirname, 'preview-src', 'index.ts'), - path.join(__dirname, 'preview-src', 'pre'), - ], - bundle: true, - minify: true, - sourcemap: false, - format: 'esm', - outdir: outDir, - platform: 'browser', - target: ['es2020'], - watch: isWatch, - incremental: isWatch, -}).catch(() => process.exit(1)); +function build() { + return esbuild.build({ + entryPoints: [ + path.join(srcDir, 'index.ts'), + path.join(srcDir, 'pre'), + ], + bundle: true, + minify: true, + sourcemap: false, + format: 'esm', + outdir: outDir, + platform: 'browser', + target: ['es2020'], + }); +} + +build().catch(() => process.exit(1)); + +if (isWatch) { + const watcher = require('@parcel/watcher'); + watcher.subscribe(srcDir, () => { + return build(); + }); +} diff --git a/extensions/markdown-math/esbuild.js b/extensions/markdown-math/esbuild.js index dd94d2e1eed..2f1899e867e 100644 --- a/extensions/markdown-math/esbuild.js +++ b/extensions/markdown-math/esbuild.js @@ -18,34 +18,45 @@ if (outputRootIndex >= 0) { outputRoot = args[outputRootIndex + 1]; } +const srcDir = path.join(__dirname, 'notebook'); const outDir = path.join(outputRoot, 'notebook-out'); -esbuild.build({ - entryPoints: [ - path.join(__dirname, 'notebook', 'katex.ts'), - ], - bundle: true, - minify: true, - sourcemap: false, - format: 'esm', - outdir: outDir, - platform: 'browser', - target: ['es2020'], - watch: isWatch, - incremental: isWatch, -}).catch(() => process.exit(1)); -fse.copySync( - path.join(__dirname, 'node_modules', 'katex', 'dist', 'katex.min.css'), - path.join(outDir, 'katex.min.css')); +async function build() { + await esbuild.build({ + entryPoints: [ + path.join(srcDir, 'katex.ts'), + ], + bundle: true, + minify: true, + sourcemap: false, + format: 'esm', + outdir: outDir, + platform: 'browser', + target: ['es2020'], + }); + fse.copySync( + path.join(__dirname, 'node_modules', 'katex', 'dist', 'katex.min.css'), + path.join(outDir, 'katex.min.css')); -const fontsDir = path.join(__dirname, 'node_modules', 'katex', 'dist', 'fonts'); -const fontsOutDir = path.join(outDir, 'fonts/'); + const fontsDir = path.join(__dirname, 'node_modules', 'katex', 'dist', 'fonts'); + const fontsOutDir = path.join(outDir, 'fonts/'); -fse.mkdirSync(fontsOutDir, { recursive: true }); + fse.mkdirSync(fontsOutDir, { recursive: true }); -for (const file of fse.readdirSync(fontsDir)) { - if (file.endsWith('.woff2')) { - fse.copyFileSync(path.join(fontsDir, file), path.join(fontsOutDir, file)); + for (const file of fse.readdirSync(fontsDir)) { + if (file.endsWith('.woff2')) { + fse.copyFileSync(path.join(fontsDir, file), path.join(fontsOutDir, file)); + } } } + + +build().catch(() => process.exit(1)); + +if (isWatch) { + const watcher = require('@parcel/watcher'); + watcher.subscribe(srcDir, () => { + return build(); + }); +} diff --git a/extensions/notebook-renderers/esbuild.js b/extensions/notebook-renderers/esbuild.js index 11a04a0a982..c374cc5fc1c 100644 --- a/extensions/notebook-renderers/esbuild.js +++ b/extensions/notebook-renderers/esbuild.js @@ -2,6 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +// @ts-check const path = require('path'); const esbuild = require('esbuild'); @@ -15,19 +16,29 @@ if (outputRootIndex >= 0) { outputRoot = args[outputRootIndex + 1]; } +const srcDir = path.join(__dirname, 'src'); const outDir = path.join(outputRoot, 'renderer-out'); -esbuild.build({ - entryPoints: [ - path.join(__dirname, 'src', 'index.ts'), - ], - bundle: true, - minify: false, - sourcemap: false, - format: 'esm', - outdir: outDir, - platform: 'browser', - target: ['es2020'], - watch: isWatch, - incremental: isWatch, -}).catch(() => process.exit(1)); +function build() { + return esbuild.build({ + entryPoints: [ + path.join(srcDir, 'index.ts'), + ], + bundle: true, + minify: false, + sourcemap: false, + format: 'esm', + outdir: outDir, + platform: 'browser', + target: ['es2020'], + }); +} + +build().catch(() => process.exit(1)); + +if (isWatch) { + const watcher = require('@parcel/watcher'); + watcher.subscribe(srcDir, () => { + return build(); + }); +} diff --git a/extensions/package.json b/extensions/package.json index f27f85fefe6..d203bc15f42 100644 --- a/extensions/package.json +++ b/extensions/package.json @@ -10,6 +10,7 @@ "postinstall": "node ./postinstall.mjs" }, "devDependencies": { + "@parcel/watcher": "2.0.5", "esbuild": "^0.11.12", "vscode-grammar-updater": "^1.0.4" } diff --git a/extensions/simple-browser/esbuild-preview.js b/extensions/simple-browser/esbuild-preview.js index d6447532501..5c8bd0610ce 100644 --- a/extensions/simple-browser/esbuild-preview.js +++ b/extensions/simple-browser/esbuild-preview.js @@ -2,6 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +// @ts-check const path = require('path'); const fs = require('fs'); const esbuild = require('esbuild'); @@ -16,27 +17,37 @@ if (outputRootIndex >= 0) { outputRoot = args[outputRootIndex + 1]; } +const srcDir = path.join(__dirname, 'preview-src'); const outDir = path.join(outputRoot, 'media'); -fs.copyFileSync( - path.join(__dirname, 'node_modules', 'vscode-codicons', 'dist', 'codicon.css'), - path.join(outDir, 'codicon.css')); +async function build() { + fs.copyFileSync( + path.join(__dirname, 'node_modules', 'vscode-codicons', 'dist', 'codicon.css'), + path.join(outDir, 'codicon.css')); -fs.copyFileSync( - path.join(__dirname, 'node_modules', 'vscode-codicons', 'dist', 'codicon.ttf'), - path.join(outDir, 'codicon.ttf')); + fs.copyFileSync( + path.join(__dirname, 'node_modules', 'vscode-codicons', 'dist', 'codicon.ttf'), + path.join(outDir, 'codicon.ttf')); -esbuild.build({ - entryPoints: [ - path.join(__dirname, 'preview-src', 'index.ts') - ], - bundle: true, - minify: true, - sourcemap: false, - format: 'esm', - outdir: outDir, - platform: 'browser', - target: ['es2020'], - watch: isWatch, - incremental: isWatch, -}).catch(() => process.exit(1)); + await esbuild.build({ + entryPoints: [ + path.join(srcDir, 'index.ts') + ], + bundle: true, + minify: true, + sourcemap: false, + format: 'esm', + outdir: outDir, + platform: 'browser', + target: ['es2020'], + }); +} + +build().catch(() => process.exit(1)); + +if (isWatch) { + const watcher = require('@parcel/watcher'); + watcher.subscribe(srcDir, () => { + return build(); + }); +} diff --git a/extensions/yarn.lock b/extensions/yarn.lock index 9ae2538a726..0d0ce02f30f 100644 --- a/extensions/yarn.lock +++ b/extensions/yarn.lock @@ -2,6 +2,14 @@ # yarn lockfile v1 +"@parcel/watcher@2.0.5": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@parcel/watcher/-/watcher-2.0.5.tgz#f913a54e1601b0aac972803829b0eece48de215b" + integrity sha512-x0hUbjv891omnkcHD7ZOhiyyUqUUR6MNjq89JhEI3BxppeKWAm6NPQsqqRrAkCJBogdT/o/My21sXtTI9rJIsw== + dependencies: + node-addon-api "^3.2.1" + node-gyp-build "^4.3.0" + coffee-script@^1.10.0: version "1.12.7" resolved "https://registry.yarnpkg.com/coffee-script/-/coffee-script-1.12.7.tgz#c05dae0cb79591d05b3070a8433a98c9a89ccc53" @@ -24,6 +32,16 @@ fast-plist@0.1.2: resolved "https://registry.yarnpkg.com/fast-plist/-/fast-plist-0.1.2.tgz#a45aff345196006d406ca6cdcd05f69051ef35b8" integrity sha1-pFr/NFGWAG1AbKbNzQX2kFHvNbg= +node-addon-api@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" + integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== + +node-gyp-build@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3" + integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q== + typescript@4.6.2: version "4.6.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4"