From bc9dac2febb372597e9a3f74ca856b52cbefb7b5 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 22 Dec 2021 11:28:05 +0100 Subject: [PATCH] Plugin Repo: Add support for source maps --- .../plugin-repo-cli/commands/updateRelease.ts | 2 ++ packages/plugin-repo-cli/index.ts | 2 ++ packages/plugin-repo-cli/package.json | 2 ++ packages/plugin-repo-cli/webpack.config.js | 20 +++++++++++++++- yarn.lock | 24 ++++++++++++++++++- 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/plugin-repo-cli/commands/updateRelease.ts b/packages/plugin-repo-cli/commands/updateRelease.ts index f3c5e70ea..cbb3e36fc 100644 --- a/packages/plugin-repo-cli/commands/updateRelease.ts +++ b/packages/plugin-repo-cli/commands/updateRelease.ts @@ -41,6 +41,8 @@ async function getPluginInfos(pluginRepoDir: string): Promise { for (const pluginDir of pluginDirs) { const basePath = `${pluginRepoDir}/plugins/${pluginDir}`; + if (!(await stat(basePath)).isDirectory()) continue; + const manifest = JSON.parse(await readFile(`${basePath}/manifest.json`, 'utf8')); output.push({ id: manifest.id, diff --git a/packages/plugin-repo-cli/index.ts b/packages/plugin-repo-cli/index.ts index 419695eef..e9c87952a 100644 --- a/packages/plugin-repo-cli/index.ts +++ b/packages/plugin-repo-cli/index.ts @@ -1,5 +1,7 @@ #!/usr/bin/env node +require('source-map-support').install(); + import * as fs from 'fs-extra'; import * as path from 'path'; import * as process from 'process'; diff --git a/packages/plugin-repo-cli/package.json b/packages/plugin-repo-cli/package.json index 277a5ab5f..571061d83 100644 --- a/packages/plugin-repo-cli/package.json +++ b/packages/plugin-repo-cli/package.json @@ -23,6 +23,7 @@ "fs-extra": "^9.0.1", "gh-release-assets": "^2.0.0", "node-fetch": "^2.6.1", + "source-map-support": "^0.5.21", "yargs": "^16.0.3" }, "devDependencies": { @@ -30,6 +31,7 @@ "@types/jest": "^26.0.15", "@types/node": "^14.14.6", "jest": "^26.6.3", + "source-map-loader": "^3.0.0", "typescript": "4.1.3", "webpack": "^5.65.0", "webpack-cli": "^4.9.1" diff --git a/packages/plugin-repo-cli/webpack.config.js b/packages/plugin-repo-cli/webpack.config.js index ebcb85eee..f6e252518 100644 --- a/packages/plugin-repo-cli/webpack.config.js +++ b/packages/plugin-repo-cli/webpack.config.js @@ -3,10 +3,19 @@ const webpack = require('webpack'); const distDir = path.resolve(__dirname, 'dist'); +// To get source maps working: +// +// - Need to add `require('source-map-support').install()` on top of index.ts +// - Set `devtool: 'source-map'` +// - It only works in development mode +// - Need to add the "source-map-loader" rule so that it uses the maps generated +// by TypeScript + module.exports = { entry: './index.js', - mode: 'production', + mode: 'development', target: 'node', + devtool: 'source-map', output: { filename: 'index.js', path: distDir, @@ -17,4 +26,13 @@ module.exports = { raw: true, }), ], + module: { + rules: [ + { + test: /\.js$/, + enforce: 'pre', + use: ['source-map-loader'], + }, + ], + }, }; diff --git a/yarn.lock b/yarn.lock index ca7cfd880..f295279a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3194,6 +3194,8 @@ __metadata: gh-release-assets: ^2.0.0 jest: ^26.6.3 node-fetch: ^2.6.1 + source-map-loader: ^3.0.0 + source-map-support: ^0.5.21 typescript: 4.1.3 webpack: ^5.65.0 webpack-cli: ^4.9.1 @@ -27023,6 +27025,13 @@ __metadata: languageName: node linkType: hard +"source-map-js@npm:^0.6.2": + version: 0.6.2 + resolution: "source-map-js@npm:0.6.2" + checksum: 9c8151a29e00fd8d3ba87709fdf9a9ce48313d653f4a29a39b4ae53d346ac79e005de624796ff42eff55cbaf26d2e87f4466001ca87831d400d818c5cf146a0e + languageName: node + linkType: hard + "source-map-js@npm:^1.0.1": version: 1.0.1 resolution: "source-map-js@npm:1.0.1" @@ -27030,6 +27039,19 @@ __metadata: languageName: node linkType: hard +"source-map-loader@npm:^3.0.0": + version: 3.0.0 + resolution: "source-map-loader@npm:3.0.0" + dependencies: + abab: ^2.0.5 + iconv-lite: ^0.6.2 + source-map-js: ^0.6.2 + peerDependencies: + webpack: ^5.0.0 + checksum: c4459cef5a43917ca1c7ad53b106ba715d545daae1ace259c867c36b2b2443c3b9eebe8630cac8f193760db39965c22d1b44d8f69e9910b88c8aca1c836757b5 + languageName: node + linkType: hard + "source-map-resolve@npm:^0.5.0, source-map-resolve@npm:^0.5.2": version: 0.5.3 resolution: "source-map-resolve@npm:0.5.3" @@ -27062,7 +27084,7 @@ __metadata: languageName: node linkType: hard -"source-map-support@npm:^0.5.13, source-map-support@npm:^0.5.16, source-map-support@npm:^0.5.19, source-map-support@npm:^0.5.6, source-map-support@npm:~0.5.20": +"source-map-support@npm:^0.5.13, source-map-support@npm:^0.5.16, source-map-support@npm:^0.5.19, source-map-support@npm:^0.5.21, source-map-support@npm:^0.5.6, source-map-support@npm:~0.5.20": version: 0.5.21 resolution: "source-map-support@npm:0.5.21" dependencies: