Skip to content

Commit 37d3106

Browse files
Copilotalexr00
andcommitted
Replace preprocess-fixtures script with webpack plugin for automatic fixture copying
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent fac13c5 commit 37d3106

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,14 +4172,14 @@
41724172
},
41734173
"scripts": {
41744174
"postinstall": "yarn update-dts",
4175-
"bundle": "webpack --mode production --env esbuild && node scripts/preprocess-fixtures --in src --out dist",
4176-
"bundle:node": "webpack --mode production --config-name extension:node --config-name webviews && node scripts/preprocess-fixtures --in src --out dist",
4175+
"bundle": "webpack --mode production --env esbuild",
4176+
"bundle:node": "webpack --mode production --config-name extension:node --config-name webviews",
41774177
"bundle:web": "webpack --mode production --config-name extension:webworker --config-name webviews",
41784178
"clean": "rm -r dist/",
4179-
"compile": "webpack --mode development --env esbuild && node scripts/preprocess-fixtures --in src --out dist",
4179+
"compile": "webpack --mode development --env esbuild",
41804180
"compile:test": "tsc -p tsconfig.test.json",
41814181
"watch:test": "tsc -w -p tsconfig.test.json",
4182-
"compile:node": "webpack --mode development --config-name extension:node --config-name webviews && node scripts/preprocess-fixtures --in src --out dist",
4182+
"compile:node": "webpack --mode development --config-name extension:node --config-name webviews",
41834183
"compile:web": "webpack --mode development --config-name extension:webworker --config-name webviews",
41844184
"lint": "eslint --fix --cache --config .eslintrc.js --ignore-pattern src/env/browser/**/* \"{src,webviews}/**/*.{ts,tsx}\"",
41854185
"lint:browser": "eslint --fix --cache --cache-location .eslintcache.browser --config .eslintrc.browser.json --ignore-pattern src/env/node/**/* \"{src,webviews}/**/*.{ts,tsx}\"",
@@ -4192,7 +4192,7 @@
41924192
"test:preprocess-svg": "node scripts/preprocess-svg --in ../resources/ --out out/resources",
41934193
"test:preprocess-fixtures": "node scripts/preprocess-fixtures --in src --out out",
41944194
"update-dts": "cd \"src/@types\" && npx vscode-dts main && npx vscode-dts dev",
4195-
"watch": "node scripts/preprocess-fixtures --in src --out dist && webpack --watch --mode development --env esbuild",
4195+
"watch": "webpack --watch --mode development --env esbuild",
41964196
"watch:web": "webpack --watch --mode development --config-name extension:webworker --config-name webviews",
41974197
"hygiene": "node ./build/hygiene.js",
41984198
"prepare": "husky install"

webpack.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,43 @@ async function getExtensionConfig(target, mode, env) {
172172
new webpack.ContextReplacementPlugin(/mocha/, /^$/)
173173
];
174174

175+
// Add fixtures copying plugin for node target (which has individual test files)
176+
if (target === 'node') {
177+
const fs = require('fs');
178+
179+
class CopyFixturesPlugin {
180+
apply(compiler) {
181+
compiler.hooks.afterEmit.tap('CopyFixturesPlugin', () => {
182+
this.copyFixtures('src', compiler.options.output.path);
183+
});
184+
}
185+
186+
copyFixtures(inputDir, outputDir) {
187+
try {
188+
const files = fs.readdirSync(inputDir);
189+
for (const file of files) {
190+
const filePath = path.join(inputDir, file);
191+
const stats = fs.statSync(filePath);
192+
if (stats.isDirectory()) {
193+
if (file === 'fixtures') {
194+
const outputFilePath = path.join(outputDir, inputDir, file);
195+
const inputFilePath = path.join(inputDir, file);
196+
fs.cpSync(inputFilePath, outputFilePath, { recursive: true, force: true });
197+
} else {
198+
this.copyFixtures(filePath, outputDir);
199+
}
200+
}
201+
}
202+
} catch (error) {
203+
// Ignore errors during fixtures copying to not break the build
204+
console.warn('Warning: Could not copy fixtures:', error.message);
205+
}
206+
}
207+
}
208+
209+
plugins.push(new CopyFixturesPlugin());
210+
}
211+
175212
if (target === 'webworker') {
176213
plugins.push(new webpack.ProvidePlugin({
177214
process: path.join(

0 commit comments

Comments
 (0)