@lynx-js/rspeedy 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +208 -0
- package/LICENSE +202 -0
- package/README.md +32 -0
- package/bin/rspeedy.js +33 -0
- package/client/hmr/WebSocketClient.js +65 -0
- package/client.d.ts +5 -0
- package/lib/api.d.ts +46 -0
- package/lib/api.js +2 -0
- package/lib/cli/build.d.ts +4 -0
- package/lib/cli/build.js +32 -0
- package/lib/cli/commands.d.ts +5 -0
- package/lib/cli/commands.js +45 -0
- package/lib/cli/dev.d.ts +4 -0
- package/lib/cli/dev.js +75 -0
- package/lib/cli/exit.d.ts +1 -0
- package/lib/cli/exit.js +51 -0
- package/lib/cli/inspect.d.ts +8 -0
- package/lib/cli/inspect.js +30 -0
- package/lib/cli/main.d.ts +1 -0
- package/lib/cli/main.js +39 -0
- package/lib/cli/preview.d.ts +4 -0
- package/lib/cli/preview.js +31 -0
- package/lib/cli/start.d.ts +6 -0
- package/lib/cli/start.js +88 -0
- package/lib/config/defaults.d.ts +2 -0
- package/lib/config/defaults.js +32 -0
- package/lib/config/defineConfig.d.ts +22 -0
- package/lib/config/defineConfig.js +24 -0
- package/lib/config/dev/client.d.ts +15 -0
- package/lib/config/dev/client.js +2 -0
- package/lib/config/dev/index.d.ts +133 -0
- package/lib/config/dev/index.js +2 -0
- package/lib/config/index.d.ts +172 -0
- package/lib/config/index.js +2 -0
- package/lib/config/loadConfig.d.ts +50 -0
- package/lib/config/loadConfig.js +98 -0
- package/lib/config/output/css-modules.d.ts +84 -0
- package/lib/config/output/css-modules.js +2 -0
- package/lib/config/output/dist-path.d.ts +68 -0
- package/lib/config/output/dist-path.js +2 -0
- package/lib/config/output/filename.d.ts +167 -0
- package/lib/config/output/filename.js +2 -0
- package/lib/config/output/index.d.ts +320 -0
- package/lib/config/output/index.js +2 -0
- package/lib/config/output/minify.d.ts +80 -0
- package/lib/config/output/minify.js +2 -0
- package/lib/config/output/source-map.d.ts +68 -0
- package/lib/config/output/source-map.js +2 -0
- package/lib/config/performance/chunk-split.d.ts +192 -0
- package/lib/config/performance/chunk-split.js +2 -0
- package/lib/config/performance/index.d.ts +50 -0
- package/lib/config/performance/index.js +2 -0
- package/lib/config/rsbuild/entry.d.ts +3 -0
- package/lib/config/rsbuild/entry.js +31 -0
- package/lib/config/rsbuild/index.d.ts +4 -0
- package/lib/config/rsbuild/index.js +70 -0
- package/lib/config/server/index.d.ts +47 -0
- package/lib/config/server/index.js +2 -0
- package/lib/config/source/decorators.d.ts +43 -0
- package/lib/config/source/decorators.js +2 -0
- package/lib/config/source/entry.d.ts +84 -0
- package/lib/config/source/entry.js +2 -0
- package/lib/config/source/index.d.ts +474 -0
- package/lib/config/source/index.js +2 -0
- package/lib/config/source/transformImport.d.ts +106 -0
- package/lib/config/source/transformImport.js +2 -0
- package/lib/config/tools/css-extract.d.ts +72 -0
- package/lib/config/tools/css-extract.js +2 -0
- package/lib/config/tools/css-loader.d.ts +130 -0
- package/lib/config/tools/css-loader.js +2 -0
- package/lib/config/tools/index.d.ts +170 -0
- package/lib/config/tools/index.js +2 -0
- package/lib/config/validate.d.ts +4 -0
- package/lib/config/validate.js +28962 -0
- package/lib/create-rspeedy.d.ts +45 -0
- package/lib/create-rspeedy.js +48 -0
- package/lib/debug.d.ts +3 -0
- package/lib/debug.js +25 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +10 -0
- package/lib/plugins/api.plugin.d.ts +3 -0
- package/lib/plugins/api.plugin.js +25 -0
- package/lib/plugins/chunkLoading.plugin.d.ts +2 -0
- package/lib/plugins/chunkLoading.plugin.js +30 -0
- package/lib/plugins/dev.plugin.d.ts +5 -0
- package/lib/plugins/dev.plugin.js +130 -0
- package/lib/plugins/index.d.ts +3 -0
- package/lib/plugins/index.js +49 -0
- package/lib/plugins/inspect.plugin.d.ts +4 -0
- package/lib/plugins/inspect.plugin.js +39 -0
- package/lib/plugins/minify.plugin.d.ts +3 -0
- package/lib/plugins/minify.plugin.js +89 -0
- package/lib/plugins/optimization.plugin.d.ts +2 -0
- package/lib/plugins/optimization.plugin.js +31 -0
- package/lib/plugins/output.plugin.d.ts +3 -0
- package/lib/plugins/output.plugin.js +34 -0
- package/lib/plugins/resolve.plugin.d.ts +2 -0
- package/lib/plugins/resolve.plugin.js +38 -0
- package/lib/plugins/rsdoctor.plugin.d.ts +3 -0
- package/lib/plugins/rsdoctor.plugin.js +41 -0
- package/lib/plugins/sourcemap.plugin.d.ts +2 -0
- package/lib/plugins/sourcemap.plugin.js +84 -0
- package/lib/plugins/stats.plugin.d.ts +2 -0
- package/lib/plugins/stats.plugin.js +20 -0
- package/lib/plugins/swc.plugin.d.ts +2 -0
- package/lib/plugins/swc.plugin.js +21 -0
- package/lib/plugins/target.plugin.d.ts +2 -0
- package/lib/plugins/target.plugin.js +12 -0
- package/lib/utils/getESVersionTarget.d.ts +1 -0
- package/lib/utils/getESVersionTarget.js +7 -0
- package/lib/utils/is-ci.d.ts +1 -0
- package/lib/utils/is-ci.js +7 -0
- package/lib/version.d.ts +4 -0
- package/lib/version.js +15 -0
- package/lib/webpack/CompilationIdPlugin.d.ts +4 -0
- package/lib/webpack/CompilationIdPlugin.js +20 -0
- package/lib/webpack/EvalSourceMapDevToolPlugin.d.ts +9 -0
- package/lib/webpack/EvalSourceMapDevToolPlugin.js +15 -0
- package/lib/webpack/ProvidePlugin.d.ts +9 -0
- package/lib/webpack/ProvidePlugin.js +15 -0
- package/lib/webpack/SourceMapDevToolPlugin.d.ts +9 -0
- package/lib/webpack/SourceMapDevToolPlugin.js +15 -0
- package/package.json +83 -0
- package/register/data.d.ts +9 -0
- package/register/hooks.js +146 -0
- package/register/index.d.ts +4 -0
- package/register/index.js +47 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function pluginResolve() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'lynx:rsbuild:resolve',
|
|
4
|
+
setup(api) {
|
|
5
|
+
api.modifyBundlerChain(chain => {
|
|
6
|
+
// dprint-ignore
|
|
7
|
+
chain
|
|
8
|
+
.resolve
|
|
9
|
+
.aliasFields
|
|
10
|
+
.add('browser')
|
|
11
|
+
.end()
|
|
12
|
+
.conditionNames
|
|
13
|
+
.add('lynx')
|
|
14
|
+
.add('import')
|
|
15
|
+
.add('require')
|
|
16
|
+
.add('browser')
|
|
17
|
+
.end()
|
|
18
|
+
.extensions
|
|
19
|
+
// Rsbuild's default is ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json']
|
|
20
|
+
// We only append `.cjs` with it.
|
|
21
|
+
.add('.cjs')
|
|
22
|
+
.end()
|
|
23
|
+
.mainFields
|
|
24
|
+
.add('lynx')
|
|
25
|
+
.add('module')
|
|
26
|
+
.add('main')
|
|
27
|
+
.end()
|
|
28
|
+
.mainFiles
|
|
29
|
+
.add('index.lynx')
|
|
30
|
+
.add('index')
|
|
31
|
+
.end()
|
|
32
|
+
.end()
|
|
33
|
+
.end();
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=resolve.plugin.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { logger } from '@rsbuild/core';
|
|
5
|
+
import { isCI } from '../utils/is-ci.js';
|
|
6
|
+
export function pluginRsdoctor(options) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'lynx:rsbuild:rsdoctor',
|
|
9
|
+
remove: ['rsbuild:rsdoctor'],
|
|
10
|
+
setup(api) {
|
|
11
|
+
if (process.env['RSDOCTOR'] !== 'true') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
api.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
|
|
15
|
+
const { RsdoctorRspackPlugin } = await import('@rsdoctor/rspack-plugin');
|
|
16
|
+
for (const config of bundlerConfigs) {
|
|
17
|
+
const pluginName = 'RsdoctorRspackPlugin';
|
|
18
|
+
const registered = config.plugins?.some((plugin) => (typeof plugin === 'object'
|
|
19
|
+
&& plugin?.['isRsdoctorPlugin'] === true)
|
|
20
|
+
|| plugin?.constructor?.name === pluginName);
|
|
21
|
+
if (registered) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
config.plugins ??= [];
|
|
25
|
+
config.plugins.push(new RsdoctorRspackPlugin({
|
|
26
|
+
// We disable client server on CI by default.
|
|
27
|
+
// But it can be overridden by `tools.rsdoctor`.
|
|
28
|
+
disableClientServer: isCI(),
|
|
29
|
+
...options,
|
|
30
|
+
supports: {
|
|
31
|
+
...options?.supports,
|
|
32
|
+
banner: true, // We must enable `supports.banner` since we have runtime wrapper enabled
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
logger.info(`Rsdoctor is enabled.`);
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=rsdoctor.plugin.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import invariant from 'tiny-invariant';
|
|
2
|
+
import { EvalSourceMapDevToolPlugin } from '../webpack/EvalSourceMapDevToolPlugin.js';
|
|
3
|
+
import { SourceMapDevToolPlugin } from '../webpack/SourceMapDevToolPlugin.js';
|
|
4
|
+
export function pluginSourcemap() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'lynx:rsbuild:sourcemap',
|
|
7
|
+
pre: ['lynx:rsbuild:dev'],
|
|
8
|
+
setup(api) {
|
|
9
|
+
api.modifyBundlerChain((chain, { isDev }) => {
|
|
10
|
+
const { dev, output, server } = api.getRsbuildConfig('current');
|
|
11
|
+
const publicPath = isDev ? dev?.assetPrefix : output?.assetPrefix;
|
|
12
|
+
if (publicPath === false) {
|
|
13
|
+
// `dev.assetPrefix === false`
|
|
14
|
+
// We do not modify the devtool option
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// If `dev.assetPrefix === true`, it should have been replaced by the `lynx:rsbuild:dev` plugin.
|
|
18
|
+
invariant(typeof publicPath === 'string' || publicPath === undefined, `dev.assetPrefix should be normalized to string, got ${dev?.assetPrefix}`);
|
|
19
|
+
applySourceMapPlugin(chain, getDevtoolFromSourceMap(), publicPath?.replaceAll('<port>', String(api.context.devServer?.port ?? server?.port)));
|
|
20
|
+
function getDevtoolFromSourceMap() {
|
|
21
|
+
const DEFAULT_DEV_DEVTOOL = 'cheap-module-source-map';
|
|
22
|
+
switch (typeof output?.sourceMap) {
|
|
23
|
+
case 'boolean': {
|
|
24
|
+
if (output.sourceMap) {
|
|
25
|
+
return isDev ? DEFAULT_DEV_DEVTOOL : 'source-map';
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
case 'undefined':
|
|
32
|
+
case 'object': {
|
|
33
|
+
return output?.sourceMap?.js
|
|
34
|
+
?? (isDev ? DEFAULT_DEV_DEVTOOL : false);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function applySourceMapPlugin(chain, devtool, publicPath) {
|
|
43
|
+
if (devtool === false) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const CHAIN_ID_DEV_SOURCEMAP = 'lynx:sourcemap';
|
|
47
|
+
const output = chain.get('output');
|
|
48
|
+
if (devtool.includes('source-map')) {
|
|
49
|
+
const hidden = devtool.includes('hidden');
|
|
50
|
+
const inline = devtool.includes('inline');
|
|
51
|
+
const evalWrapped = devtool.includes('eval');
|
|
52
|
+
const cheap = devtool.includes('cheap');
|
|
53
|
+
const moduleMaps = devtool.includes('module');
|
|
54
|
+
const noSources = devtool.includes('nosources'); // cSpell:disable-line
|
|
55
|
+
const options = {
|
|
56
|
+
filename: inline
|
|
57
|
+
? null
|
|
58
|
+
: (output?.sourceMapFilename ?? '[file].map[query]'),
|
|
59
|
+
moduleFilenameTemplate: output?.devtoolModuleFilenameTemplate
|
|
60
|
+
?? 'file://[absolute-resource-path]',
|
|
61
|
+
fallbackModuleFilenameTemplate: output
|
|
62
|
+
?.devtoolFallbackModuleFilenameTemplate
|
|
63
|
+
?? 'file://[absolute-resource-path]?[hash]',
|
|
64
|
+
append: hidden ? false : undefined,
|
|
65
|
+
module: moduleMaps ? true : !cheap,
|
|
66
|
+
columns: !cheap,
|
|
67
|
+
noSources,
|
|
68
|
+
namespace: output?.devtoolNamespace,
|
|
69
|
+
publicPath,
|
|
70
|
+
};
|
|
71
|
+
chain
|
|
72
|
+
// If you want to use a custom configuration for this plugin in development mode
|
|
73
|
+
// Make sure to disable the default one. I.e. set `devtool: false`.
|
|
74
|
+
// See: https://webpack.js.org/plugins/source-map-dev-tool-plugin/
|
|
75
|
+
.devtool(false)
|
|
76
|
+
.plugin(CHAIN_ID_DEV_SOURCEMAP)
|
|
77
|
+
.when(evalWrapped, plugin => plugin.use(EvalSourceMapDevToolPlugin, [
|
|
78
|
+
options,
|
|
79
|
+
]), plugin => plugin.use(SourceMapDevToolPlugin, [
|
|
80
|
+
options,
|
|
81
|
+
]));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=sourcemap.plugin.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function pluginStats() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'lynx:rsbuild:stats',
|
|
4
|
+
setup(api) {
|
|
5
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
6
|
+
return mergeRsbuildConfig(config, {
|
|
7
|
+
performance: {
|
|
8
|
+
bundleAnalyze: {
|
|
9
|
+
// Failed to parse background.js, so analyzerMode is disabled here.
|
|
10
|
+
// Please use Webpack Bundle Analyzer in rsdoctor.
|
|
11
|
+
analyzerMode: 'disabled',
|
|
12
|
+
generateStatsFile: true,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=stats.plugin.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getESVersionTarget } from '../utils/getESVersionTarget.js';
|
|
2
|
+
export function pluginSwc() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'lynx:rsbuild:swc',
|
|
5
|
+
setup(api) {
|
|
6
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
7
|
+
return mergeRsbuildConfig(config, {
|
|
8
|
+
tools: {
|
|
9
|
+
swc(config) {
|
|
10
|
+
delete config.env;
|
|
11
|
+
config.jsc ??= {};
|
|
12
|
+
// TODO(target): use configuration
|
|
13
|
+
config.jsc.target = getESVersionTarget();
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=swc.plugin.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getESVersionTarget } from '../utils/getESVersionTarget.js';
|
|
2
|
+
export function pluginTarget() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'lynx:rsbuild:target',
|
|
5
|
+
setup(api) {
|
|
6
|
+
api.modifyBundlerChain((options) => {
|
|
7
|
+
options.target([getESVersionTarget()]);
|
|
8
|
+
});
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=target.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getESVersionTarget(): 'es2015' | 'es2019';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export function getESVersionTarget() {
|
|
5
|
+
return process.env['NODE_ENV'] === 'production' ? 'es2015' : 'es2019';
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=getESVersionTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isCI(): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export function isCI() {
|
|
5
|
+
return !!process.env['CI'] && process.env['CI'] !== 'false';
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=is-ci.js.map
|
package/lib/version.d.ts
ADDED
package/lib/version.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { rspack } from '@rsbuild/core';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
// Using `import('../package.json', { with: { type: 'json' } })` will cause NodeJS print a
|
|
8
|
+
// experimental warning.
|
|
9
|
+
// eslint-disable-next-line import/no-commonjs
|
|
10
|
+
const pkg = require('../package.json');
|
|
11
|
+
const version = pkg.version;
|
|
12
|
+
export const rspackVersion = rspack.rspackVersion;
|
|
13
|
+
export { version };
|
|
14
|
+
export { version as rsbuildVersion } from '@rsbuild/core';
|
|
15
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class CompilationIdPlugin {
|
|
2
|
+
apply(compiler) {
|
|
3
|
+
// We need `compiler.name` and `compiler.options.output.uniqueName` to be set
|
|
4
|
+
// before we can get the compilation id
|
|
5
|
+
compiler.hooks.initialize.tap('CompilationIdPlugin', () => {
|
|
6
|
+
const { DefinePlugin } = compiler.webpack;
|
|
7
|
+
new DefinePlugin({
|
|
8
|
+
RSPEEDY_COMPILATION_ID: JSON.stringify(getCompilationId(compiler)),
|
|
9
|
+
}).apply(compiler);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// Copied from https://github.com/web-infra-dev/rsbuild/blob/ce031b589a0f97f04454be5c2159d72ce5deea61/packages/core/src/server/helper.ts#L448-L455
|
|
14
|
+
// A unique name for WebSocket communication
|
|
15
|
+
const COMPILATION_ID_REGEX = /[^\w-]/g;
|
|
16
|
+
function getCompilationId(compiler) {
|
|
17
|
+
const uniqueName = compiler.options.output.uniqueName ?? '';
|
|
18
|
+
return `${compiler.name ?? ''}_${uniqueName.replace(COMPILATION_ID_REGEX, '_')}`;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=CompilationIdPlugin.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
/**
|
|
3
|
+
* A shim to `webpack.EvalSourceMapDevToolPlugin`. Can be used in both webpack & rspack.
|
|
4
|
+
*/
|
|
5
|
+
export declare class EvalSourceMapDevToolPlugin {
|
|
6
|
+
options: Rspack.SourceMapDevToolPluginOptions;
|
|
7
|
+
constructor(options: Rspack.SourceMapDevToolPluginOptions);
|
|
8
|
+
apply(compiler: Rspack.Compiler): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shim to `webpack.EvalSourceMapDevToolPlugin`. Can be used in both webpack & rspack.
|
|
3
|
+
*/
|
|
4
|
+
export class EvalSourceMapDevToolPlugin {
|
|
5
|
+
options;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
// Using `webpack.Compiler` to get typescript check in webpack-chain of rsbuild
|
|
10
|
+
apply(compiler) {
|
|
11
|
+
const { EvalSourceMapDevToolPlugin } = compiler.webpack;
|
|
12
|
+
new EvalSourceMapDevToolPlugin(this.options).apply(compiler);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=EvalSourceMapDevToolPlugin.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
/**
|
|
3
|
+
* A shim to `webpack.ProvidePlugin`. Can be used in both webpack & rspack.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ProvidePlugin {
|
|
6
|
+
definitions: Record<string, string | string[]>;
|
|
7
|
+
constructor(definitions: Record<string, string | string[]>);
|
|
8
|
+
apply(compiler: Rspack.Compiler): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shim to `webpack.ProvidePlugin`. Can be used in both webpack & rspack.
|
|
3
|
+
*/
|
|
4
|
+
export class ProvidePlugin {
|
|
5
|
+
definitions;
|
|
6
|
+
constructor(definitions) {
|
|
7
|
+
this.definitions = definitions;
|
|
8
|
+
}
|
|
9
|
+
// Using `webpack.Compiler` to get typescript check in webpack-chain of rsbuild
|
|
10
|
+
apply(compiler) {
|
|
11
|
+
const { ProvidePlugin } = compiler.webpack;
|
|
12
|
+
new ProvidePlugin(this.definitions).apply(compiler);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ProvidePlugin.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
/**
|
|
3
|
+
* A shim to `webpack.SourceMapDevToolPlugin`. Can be used in both webpack & rspack.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SourceMapDevToolPlugin {
|
|
6
|
+
options: Rspack.SourceMapDevToolPluginOptions;
|
|
7
|
+
constructor(options: Rspack.SourceMapDevToolPluginOptions);
|
|
8
|
+
apply(compiler: Rspack.Compiler): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shim to `webpack.SourceMapDevToolPlugin`. Can be used in both webpack & rspack.
|
|
3
|
+
*/
|
|
4
|
+
export class SourceMapDevToolPlugin {
|
|
5
|
+
options;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
// Using `webpack.Compiler` to get typescript check in webpack-chain of rsbuild
|
|
10
|
+
apply(compiler) {
|
|
11
|
+
const { SourceMapDevToolPlugin } = compiler.webpack;
|
|
12
|
+
new SourceMapDevToolPlugin(this.options).apply(compiler);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=SourceMapDevToolPlugin.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lynx-js/rspeedy",
|
|
3
|
+
"version": "0.8.2",
|
|
4
|
+
"description": "A webpack/rspack-based frontend toolchain for Lynx",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"webpack",
|
|
7
|
+
"rspack",
|
|
8
|
+
"Lynx",
|
|
9
|
+
"ReactLynx"
|
|
10
|
+
],
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Qingyu Wang",
|
|
14
|
+
"email": "colinwang.0616@gmail.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/index.d.ts",
|
|
20
|
+
"import": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./client": {
|
|
23
|
+
"types": "./client.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./register": {
|
|
26
|
+
"types": "./register/index.d.ts",
|
|
27
|
+
"import": "./register/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"types": "./lib/index.d.ts",
|
|
32
|
+
"bin": {
|
|
33
|
+
"rspeedy": "./bin/rspeedy.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"bin",
|
|
37
|
+
"client",
|
|
38
|
+
"lib",
|
|
39
|
+
"!lib/**/*.js.map",
|
|
40
|
+
"register",
|
|
41
|
+
"client.d.ts",
|
|
42
|
+
"CHANGELOG.md",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@microsoft/api-extractor": "7.51.0",
|
|
47
|
+
"@rsbuild/core": "1.2.11",
|
|
48
|
+
"@rsbuild/plugin-css-minimizer": "1.0.2",
|
|
49
|
+
"@rsdoctor/rspack-plugin": "^0.4.13",
|
|
50
|
+
"chokidar": "^4.0.3",
|
|
51
|
+
"commander": "^13.1.0",
|
|
52
|
+
"default-gateway": "^7.2.2",
|
|
53
|
+
"exit-hook": "^4.0.0",
|
|
54
|
+
"ipaddr.js": "^2.2.0",
|
|
55
|
+
"javascript-stringify": "^2.1.0",
|
|
56
|
+
"picocolors": "^1.1.1",
|
|
57
|
+
"tiny-invariant": "^1.3.3",
|
|
58
|
+
"ts-blank-space": "^0.6.0",
|
|
59
|
+
"typia": "7.6.4",
|
|
60
|
+
"@lynx-js/chunk-loading-webpack-plugin": "^0.1.6",
|
|
61
|
+
"@lynx-js/webpack-dev-transport": "^0.1.0",
|
|
62
|
+
"@lynx-js/websocket": "^0.0.3"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
66
|
+
"@rsbuild/webpack": "1.2.3",
|
|
67
|
+
"@types/default-gateway": "^7.2.2",
|
|
68
|
+
"eventemitter3": "^5.0.1",
|
|
69
|
+
"type-fest": "^4.35.0",
|
|
70
|
+
"vitest": "^3.0.7",
|
|
71
|
+
"webpack": "^5.98.0",
|
|
72
|
+
"@lynx-js/vitest-setup": "0.0.0"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=18"
|
|
76
|
+
},
|
|
77
|
+
"tsdocMetadata": "./lib/tsdoc-metadata.json",
|
|
78
|
+
"scripts": {
|
|
79
|
+
"api-extractor": "api-extractor run --verbose",
|
|
80
|
+
"test": "pnpm -w run test --project rspeedy",
|
|
81
|
+
"test:type": "vitest --typecheck.only"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import type { MessagePort } from 'node:worker_threads'
|
|
6
|
+
|
|
7
|
+
export interface Data {
|
|
8
|
+
port: MessagePort
|
|
9
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
// Copyright 2024 Bloomberg Finance L.P.
|
|
6
|
+
// Distributed under the terms of the Apache 2.0 license.
|
|
7
|
+
|
|
8
|
+
// @ts-check
|
|
9
|
+
|
|
10
|
+
import { URL } from 'node:url'
|
|
11
|
+
|
|
12
|
+
import tsBlankSpace from 'ts-blank-space'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @type {{ active: boolean; port: import('worker_threads').MessagePort | null }}
|
|
16
|
+
*/
|
|
17
|
+
const state = {
|
|
18
|
+
active: true,
|
|
19
|
+
port: null,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {import('./data').Data} Data
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The `initialize` hook provides a way to define a custom function that runs in the hooks thread
|
|
28
|
+
* when the hooks module is initialized. Initialization happens when the hooks module is registered via `register`.
|
|
29
|
+
*
|
|
30
|
+
* This hook can receive data from a `register` invocation, including ports and other transferrable objects.
|
|
31
|
+
* The return value of `initialize` can be a `Promise`, in which case it will be awaited before the main application thread execution resumes.
|
|
32
|
+
*
|
|
33
|
+
* @type {import('module').InitializeHook<Data>}
|
|
34
|
+
*/
|
|
35
|
+
export const initialize = function initialize(
|
|
36
|
+
data,
|
|
37
|
+
) {
|
|
38
|
+
state.port = data.port
|
|
39
|
+
data.port.on('message', onMessage)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The `resolve` hook chain is responsible for resolving file URL for a given module specifier and parent URL, and optionally its format (such as `'module'`) as a hint to the `load` hook.
|
|
44
|
+
* If a format is specified, the load hook is ultimately responsible for providing the final `format` value (and it is free to ignore the hint provided by `resolve`);
|
|
45
|
+
* if `resolve` provides a format, a custom `load` hook is required even if only to pass the value to the Node.js default `load` hook.
|
|
46
|
+
*
|
|
47
|
+
* @type {import('module').ResolveHook}
|
|
48
|
+
*/
|
|
49
|
+
export const resolve = async function resolve(
|
|
50
|
+
specifier,
|
|
51
|
+
context,
|
|
52
|
+
nextResolve,
|
|
53
|
+
) {
|
|
54
|
+
try {
|
|
55
|
+
return await nextResolve(specifier, context)
|
|
56
|
+
} catch (err) {
|
|
57
|
+
const url = parseURL(err?.url)
|
|
58
|
+
if (
|
|
59
|
+
state.active && url?.pathname.endsWith('.js')
|
|
60
|
+
) {
|
|
61
|
+
try {
|
|
62
|
+
return await nextResolve(
|
|
63
|
+
// Try `.ts` when resolve failed.
|
|
64
|
+
url.pathname.slice(0, -'.js'.length) + '.ts',
|
|
65
|
+
context,
|
|
66
|
+
)
|
|
67
|
+
} catch {
|
|
68
|
+
// Can't not resolve `.ts`, too.
|
|
69
|
+
// Throw the original error.
|
|
70
|
+
throw err
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw err
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The `load` hook provides a way to define a custom method of determining how a URL should be interpreted, retrieved, and parsed.
|
|
79
|
+
* It is also in charge of validating the import assertion.
|
|
80
|
+
*
|
|
81
|
+
* @type {import('module').LoadHook}
|
|
82
|
+
*/
|
|
83
|
+
export const load = async function load(url, context, nextLoad) {
|
|
84
|
+
const fullURL = parseURL(url)
|
|
85
|
+
|
|
86
|
+
if (!fullURL) {
|
|
87
|
+
return nextLoad(url, context)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { pathname } = fullURL
|
|
91
|
+
|
|
92
|
+
const isCts = pathname.endsWith('.cts')
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
!(pathname.endsWith('.ts')
|
|
96
|
+
|| pathname.endsWith('.mts')
|
|
97
|
+
|| isCts)
|
|
98
|
+
|| !state.active
|
|
99
|
+
) {
|
|
100
|
+
return nextLoad(url, context)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const result = await nextLoad(url, { ...context, format: 'module' })
|
|
104
|
+
const transformedSource = tsBlankSpace(
|
|
105
|
+
// @ts-expect-error result.source should not be `undefined`
|
|
106
|
+
result.source.toString(),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
format: isCts ? 'commonjs' : 'module',
|
|
111
|
+
shortCircuit: true,
|
|
112
|
+
source: transformedSource + '\n//# sourceURL=' + url,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The callback of the `onmessage` of worker_thread.
|
|
118
|
+
*
|
|
119
|
+
* @param {string} message - The posted message from main-thread
|
|
120
|
+
*/
|
|
121
|
+
function onMessage(message) {
|
|
122
|
+
if (message === 'deactivate') {
|
|
123
|
+
state.active = false
|
|
124
|
+
}
|
|
125
|
+
state.port?.off('message', onMessage)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Similar with `URL.parse(url, 'file://')`.
|
|
130
|
+
*
|
|
131
|
+
* We are doing this since `URL.parse` is only supported in NodeJS 22.
|
|
132
|
+
*
|
|
133
|
+
* @param {string | undefined | null} url - The url string.
|
|
134
|
+
* @returns {URL | null} The URL parsed by `new URL`
|
|
135
|
+
*/
|
|
136
|
+
function parseURL(url) {
|
|
137
|
+
if (url === null || url === undefined) {
|
|
138
|
+
return null
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
return new URL(url, 'file://')
|
|
143
|
+
} catch {
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
}
|