diff --git a/packages/config-jest/package.json b/packages/config-jest/package.json index 58ce3387..aa5ee269 100644 --- a/packages/config-jest/package.json +++ b/packages/config-jest/package.json @@ -17,7 +17,7 @@ }, "scripts": { "clean": "rm -rf dist", - "build": "rm -rf dist config && tsc -p tsconfig.build.json && node scripts/post-build.js", + "build": "rm -rf dist config && tsc -p tsconfig.build.json && node scripts/post-build.mjs", "lint": "eslint --max-warnings=0 src", "test": "echo 'No test in @reskript/config-jest'" }, diff --git a/packages/config-jest/scripts/post-build.js b/packages/config-jest/scripts/post-build.mjs similarity index 86% rename from packages/config-jest/scripts/post-build.js rename to packages/config-jest/scripts/post-build.mjs index acd53230..8f36b196 100644 --- a/packages/config-jest/scripts/post-build.js +++ b/packages/config-jest/scripts/post-build.mjs @@ -1,7 +1,8 @@ -const fs = require('fs'); -const path = require('path'); -const prettier = require('prettier'); -const {getJestPresetConfig} = require('../dist'); +import fs from 'fs'; +import path from 'path'; +import prettier from 'prettier'; +import {dirFromImportMeta} from '@reskript/core'; +import {getJestPresetConfig} from '../dist/index.js'; const dumpAsModule = (json, destination) => { // 有几个东西是用了`resolve('xxx')`变成了绝对路径,在这里要换回来再替换成`require.resolve` @@ -41,7 +42,7 @@ const dumpAsModule = (json, destination) => { }; const jestPresetConfig = target => getJestPresetConfig(target, '%RESKRIPT_NODE_MODULE_JEST_PATH%'); -const destination = path.join(__dirname, '..', 'config'); +const destination = path.join(dirFromImportMeta(import.meta.url), '..', 'config'); fs.mkdirSync(destination, {recursive: true}); dumpAsModule(jestPresetConfig('react'), path.join(destination, 'jest-react.js')); dumpAsModule(jestPresetConfig('node'), path.join(destination, 'jest-node.js')); diff --git a/packages/webpack-plugin-extra-script/package.json b/packages/webpack-plugin-extra-script/package.json index 5d7ca9c6..376a9286 100644 --- a/packages/webpack-plugin-extra-script/package.json +++ b/packages/webpack-plugin-extra-script/package.json @@ -24,6 +24,7 @@ "test": "vitest run" }, "devDependencies": { + "@reskript/core": "3.0.2", "@types/node": "^17.0.4", "c8": "^7.10.0", "eslint": "^8.6.0", diff --git a/packages/webpack-plugin-extra-script/src/__tests__/compiler.ts b/packages/webpack-plugin-extra-script/src/__tests__/compiler.ts index c6f5ea9e..899e1bef 100644 --- a/packages/webpack-plugin-extra-script/src/__tests__/compiler.ts +++ b/packages/webpack-plugin-extra-script/src/__tests__/compiler.ts @@ -2,17 +2,20 @@ import path from 'path'; import fs from 'fs'; import webpack from 'webpack'; import HTMLWebpackPlugin from 'html-webpack-plugin'; +import {dirFromImportMeta} from '@reskript/core'; import {ScriptFactory, Options} from '../interface'; -import ExtraScriptPlugin from '../index'; +import ExtraScriptPlugin from '../index.js'; + +const currentDirectory = dirFromImportMeta(import.meta.url); export default (scriptOrFactory: ScriptFactory, options?: Options) => { const compiler = webpack({ devtool: false, mode: 'development', - context: __dirname, + context: currentDirectory, entry: './fixtures/index.js', output: { - path: path.join(__dirname, 'output'), + path: path.join(currentDirectory, 'output'), filename: 'bundle.js', }, plugins: [ @@ -39,7 +42,7 @@ export default (scriptOrFactory: ScriptFactory, options?: Options) => { reject(new Error(result?.errors?.[0].message ?? 'Unknown error')); } - const output = fs.readFileSync(path.join(__dirname, 'output', 'index.html'), 'utf-8'); + const output = fs.readFileSync(path.join(currentDirectory, 'output', 'index.html'), 'utf-8'); resolve(output); }); }); diff --git a/packages/webpack-plugin-interpolate-html/package.json b/packages/webpack-plugin-interpolate-html/package.json index eaa4d8ac..7b1f6474 100644 --- a/packages/webpack-plugin-interpolate-html/package.json +++ b/packages/webpack-plugin-interpolate-html/package.json @@ -24,6 +24,7 @@ "test": "vitest run" }, "devDependencies": { + "@reskript/core": "3.0.2", "@types/node": "^17.0.4", "c8": "^7.10.0", "eslint": "^8.6.0", diff --git a/packages/webpack-plugin-interpolate-html/src/__tests__/compiler.ts b/packages/webpack-plugin-interpolate-html/src/__tests__/compiler.ts index ee742569..e002cfb4 100644 --- a/packages/webpack-plugin-interpolate-html/src/__tests__/compiler.ts +++ b/packages/webpack-plugin-interpolate-html/src/__tests__/compiler.ts @@ -2,20 +2,23 @@ import path from 'path'; import fs from 'fs'; import webpack from 'webpack'; import HTMLWebpackPlugin from 'html-webpack-plugin'; -import InteroplateHTMLPlugin from '../index'; +import {dirFromImportMeta} from '@reskript/core'; +import InteroplateHTMLPlugin from '../index.js'; + +const currentDirectory = dirFromImportMeta(import.meta.url); export default (replacements: Record) => { const compiler = webpack({ devtool: false, mode: 'development', - context: __dirname, + context: currentDirectory, entry: './fixtures/index.js', output: { - path: path.join(__dirname, 'output'), + path: path.join(currentDirectory, 'output'), filename: 'bundle.js', }, plugins: [ - new HTMLWebpackPlugin({template: path.join(__dirname, 'fixtures', 'index.html')}), + new HTMLWebpackPlugin({template: path.join(currentDirectory, 'fixtures', 'index.html')}), new InteroplateHTMLPlugin(replacements), ], }); @@ -38,7 +41,7 @@ export default (replacements: Record) => { reject(new Error(result?.errors?.[0].message ?? 'Unknown error')); } - const output = fs.readFileSync(path.join(__dirname, 'output', 'index.html'), 'utf-8'); + const output = fs.readFileSync(path.join(currentDirectory, 'output', 'index.html'), 'utf-8'); resolve(output); }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab13e496..51ba63ce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1075,6 +1075,7 @@ importers: packages/webpack-plugin-extra-script: specifiers: + '@reskript/core': 3.0.2 '@types/node': ^17.0.4 c8: ^7.10.0 eslint: ^8.6.0 @@ -1084,6 +1085,7 @@ importers: vitest: ^0.0.115 webpack: ^5.65.0 devDependencies: + '@reskript/core': link:../core '@types/node': 17.0.8 c8: 7.11.0 eslint: 8.6.0 @@ -1095,6 +1097,7 @@ importers: packages/webpack-plugin-interpolate-html: specifiers: + '@reskript/core': 3.0.2 '@types/node': ^17.0.4 c8: ^7.10.0 escape-string-regexp: ^5.0.0 @@ -1107,6 +1110,7 @@ importers: dependencies: escape-string-regexp: 5.0.0 devDependencies: + '@reskript/core': link:../core '@types/node': 17.0.8 c8: 7.11.0 eslint: 8.6.0