Skip to content

Commit

Permalink
refactor: 迁移ESM的收尾调整 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
otakustay committed Jan 15, 2022
1 parent 475c02f commit 9eec55a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/config-jest/package.json
Expand Up @@ -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'"
},
Expand Down
@@ -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`
Expand Down Expand Up @@ -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'));
1 change: 1 addition & 0 deletions packages/webpack-plugin-extra-script/package.json
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions packages/webpack-plugin-extra-script/src/__tests__/compiler.ts
Expand Up @@ -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: [
Expand All @@ -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);
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-plugin-interpolate-html/package.json
Expand Up @@ -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",
Expand Down
Expand Up @@ -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<string, string>) => {
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),
],
});
Expand All @@ -38,7 +41,7 @@ export default (replacements: Record<string, string>) => {
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);
});
});
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9eec55a

Please sign in to comment.