@moneko/core 3.2.1-beta.1 → 3.2.1-beta.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/lib/app-entry.js +32 -1
- package/lib/app.js +40 -2
- package/lib/cleanup.js +19 -1
- package/lib/common.js +248 -1
- package/lib/config.js +234 -1
- package/lib/coverage.js +33 -2
- package/lib/dev.js +89 -5
- package/lib/docs.js +120 -2
- package/lib/done.js +12 -1
- package/lib/esm.js +7 -1
- package/lib/fallback.js +6 -1
- package/lib/generate-api.js +345 -14
- package/lib/has-pkg.js +12 -1
- package/lib/html-add-entry-attr.js +32 -10
- package/lib/html-plugin-option.js +45 -1
- package/lib/index.js +4 -1
- package/lib/locales.js +93 -3
- package/lib/merge-router.js +1 -1
- package/lib/minify.js +47 -2
- package/lib/modify-vars.js +11 -1
- package/lib/module-federation.js +46 -1
- package/lib/module.config.js +273 -3
- package/lib/net.js +33 -1
- package/lib/normalize-css.js +6 -1
- package/lib/paths.js +21 -1
- package/lib/polyfills/replace-children.js +26 -3
- package/lib/polyfills.js +15 -3
- package/lib/prefix-router.js +6 -1
- package/lib/process-env.js +33 -2
- package/lib/prod.js +65 -5
- package/lib/reactive-object.js +47 -8
- package/lib/rem.js +6 -1
- package/lib/resolver-sync.js +27 -1
- package/lib/routes.js +196 -4
- package/lib/seo.js +41 -2
- package/lib/swcrc.js +100 -2
- package/lib/tsloader.config.js +26 -2
- package/lib/utils.js +71 -7
- package/lib/virtual-module-plugin.js +49 -1
- package/lib/virtual-modules.js +37 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +4 -2
- package/typings/global.d.ts +1 -2
- package/lib/threads.d.ts +0 -1
- package/lib/threads.js +0 -3
package/lib/swcrc.js
CHANGED
|
@@ -1,2 +1,100 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
1
|
+
import { merge } from 'webpack-merge';
|
|
2
|
+
import { CONFIG } from './config.js';
|
|
3
|
+
import paths from './paths.js';
|
|
4
|
+
import polyfills from './polyfills.js';
|
|
5
|
+
import { isReact, isSolid, jsxImportSource } from './process-env.js';
|
|
6
|
+
export const swcMinifyOption = {
|
|
7
|
+
compress: {
|
|
8
|
+
top_retain: [],
|
|
9
|
+
keep_infinity: true,
|
|
10
|
+
global_defs: {
|
|
11
|
+
'@alert': 'console.log'
|
|
12
|
+
},
|
|
13
|
+
pure_funcs: [
|
|
14
|
+
'console.log',
|
|
15
|
+
'console.warn',
|
|
16
|
+
'console.error',
|
|
17
|
+
'console.info'
|
|
18
|
+
],
|
|
19
|
+
toplevel: false,
|
|
20
|
+
drop_console: true,
|
|
21
|
+
drop_debugger: true,
|
|
22
|
+
module: false,
|
|
23
|
+
ecma: 2015,
|
|
24
|
+
ie8: false,
|
|
25
|
+
keep_classnames: void 0,
|
|
26
|
+
keep_fnames: false
|
|
27
|
+
},
|
|
28
|
+
mangle: true
|
|
29
|
+
};
|
|
30
|
+
function transformConfigs(config) {
|
|
31
|
+
for(let i = 0, ks = Object.keys(config), l = ks.length; i < l; i++){
|
|
32
|
+
config[ks[i]].transform = `${ks[i]}/${config[ks[i]].transform}`;
|
|
33
|
+
if (config[ks[i]].style) {
|
|
34
|
+
config[ks[i]].style = `${ks[i]}/${config[ks[i]].style}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
39
|
+
export default ((isDev = false)=>{
|
|
40
|
+
const swcOption = {
|
|
41
|
+
module: {
|
|
42
|
+
type: 'es6',
|
|
43
|
+
resolveFully: true
|
|
44
|
+
},
|
|
45
|
+
jsc: {
|
|
46
|
+
parser: {
|
|
47
|
+
syntax: 'typescript',
|
|
48
|
+
tsx: true,
|
|
49
|
+
decorators: true,
|
|
50
|
+
dynamicImport: true
|
|
51
|
+
},
|
|
52
|
+
loose: true,
|
|
53
|
+
target: 'es2017',
|
|
54
|
+
externalHelpers: true,
|
|
55
|
+
transform: {
|
|
56
|
+
legacyDecorator: true,
|
|
57
|
+
decoratorMetadata: true,
|
|
58
|
+
react: {
|
|
59
|
+
runtime: 'automatic',
|
|
60
|
+
throwIfNamespace: true,
|
|
61
|
+
refresh: isReact && isDev,
|
|
62
|
+
development: isDev,
|
|
63
|
+
importSource: jsxImportSource
|
|
64
|
+
},
|
|
65
|
+
optimizer: {
|
|
66
|
+
simplify: false
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
experimental: {
|
|
70
|
+
emitAssertForImportAttributes: true,
|
|
71
|
+
cacheRoot: paths.swcCachePath,
|
|
72
|
+
plugins: [
|
|
73
|
+
[
|
|
74
|
+
'swc-plugin-another-transform-imports',
|
|
75
|
+
transformConfigs(CONFIG.importOnDemand || {})
|
|
76
|
+
],
|
|
77
|
+
isSolid && [
|
|
78
|
+
'@moneko/jsx-dom-expressions',
|
|
79
|
+
CONFIG.jsxDomExpressions || {}
|
|
80
|
+
]
|
|
81
|
+
].filter(Boolean)
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
sourceMaps: true,
|
|
85
|
+
parseMap: true
|
|
86
|
+
};
|
|
87
|
+
if (CONFIG.polyfill) {
|
|
88
|
+
swcOption.jsc.target = void 0;
|
|
89
|
+
// swc polyfill,会复用 babel 链路,但效率比 babel 低
|
|
90
|
+
swcOption.env = {
|
|
91
|
+
include: polyfills(),
|
|
92
|
+
mode: 'usage',
|
|
93
|
+
coreJs: '3.32.2'
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (CONFIG.swcrc) {
|
|
97
|
+
return merge(swcOption, typeof CONFIG.swcrc === 'function' ? CONFIG.swcrc(isDev) : CONFIG.swcrc);
|
|
98
|
+
}
|
|
99
|
+
return swcOption;
|
|
100
|
+
});
|
package/lib/tsloader.config.js
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import transformerFactory from 'ts-import-plugin';
|
|
3
|
+
import merge from 'webpack-merge';
|
|
4
|
+
import { CONFIG } from './config.js';
|
|
5
|
+
import { isFunction, readConf, resolveProgramPath } from './utils.js';
|
|
6
|
+
const importOnDemand = [];
|
|
7
|
+
if (Array.isArray(CONFIG.importOnDemand)) {
|
|
8
|
+
Object.assign(importOnDemand, CONFIG.importOnDemand.map((item)=>transformerFactory(item)));
|
|
9
|
+
}
|
|
10
|
+
const beforeTransformers = [
|
|
11
|
+
...importOnDemand
|
|
12
|
+
];
|
|
13
|
+
let tsLoaderConfig = {
|
|
14
|
+
transpileOnly: true,
|
|
15
|
+
getCustomTransformers: ()=>({
|
|
16
|
+
before: beforeTransformers
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const customTsloaderConfigPath = resolveProgramPath('tsloader.config.ts');
|
|
21
|
+
fs.accessSync(customTsloaderConfigPath, fs.constants.R_OK);
|
|
22
|
+
const customTsloaderConfig = (await readConf(customTsloaderConfigPath, 'tsloader.config')).default;
|
|
23
|
+
tsLoaderConfig = merge(tsLoaderConfig, isFunction(customTsloaderConfig) ? customTsloaderConfig(process) : customTsloaderConfig);
|
|
24
|
+
// eslint-disable-next-line no-empty
|
|
25
|
+
} catch (error) {}
|
|
26
|
+
export default tsLoaderConfig;
|
package/lib/utils.js
CHANGED
|
@@ -1,15 +1,79 @@
|
|
|
1
|
-
import{readFileSync
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { transformFileSync } from '@swc/core';
|
|
4
|
+
import paths from './paths.js';
|
|
5
|
+
import resolverSync from './resolver-sync.js';
|
|
6
|
+
const exportPattern = /export\s+(?:async\s+)?(?:function|const)\s+(\w+)/g;
|
|
7
|
+
/** 获取导出标识
|
|
2
8
|
* @param {string} path 文件地址
|
|
3
9
|
* @returns {string[]} 包含的标识
|
|
4
|
-
*/export function getExportTokens(
|
|
10
|
+
*/ export function getExportTokens(path) {
|
|
11
|
+
const code = readFileSync(path, {
|
|
12
|
+
encoding: 'utf-8'
|
|
13
|
+
});
|
|
14
|
+
const tokens = [];
|
|
15
|
+
let match;
|
|
16
|
+
while(match = exportPattern.exec(code)){
|
|
17
|
+
if (!tokens.includes(match[1])) {
|
|
18
|
+
tokens.push(match[1]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return tokens;
|
|
22
|
+
}
|
|
23
|
+
const swcOption = {
|
|
24
|
+
inputSourceMap: false,
|
|
25
|
+
sourceMaps: false,
|
|
26
|
+
module: {
|
|
27
|
+
type: 'es6'
|
|
28
|
+
},
|
|
29
|
+
jsc: {
|
|
30
|
+
parser: {
|
|
31
|
+
syntax: 'typescript'
|
|
32
|
+
},
|
|
33
|
+
loose: false
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export function tfc(filepath) {
|
|
37
|
+
return transformFileSync(filepath, swcOption).code || '{}';
|
|
38
|
+
}
|
|
39
|
+
export function readConf(src, name) {
|
|
40
|
+
const cacheFile = `${paths.cachePath}/${name}.mjs`;
|
|
41
|
+
writeFileSync(cacheFile, tfc(src), 'utf-8');
|
|
42
|
+
return import(cacheFile);
|
|
43
|
+
}
|
|
44
|
+
export function toUpperCaseString(string) {
|
|
45
|
+
return string?.replace(/\b\w/g, (th)=>th.toUpperCase()).replace(/\./g, ' ');
|
|
46
|
+
}
|
|
47
|
+
/** 位于项目根目录下的位置
|
|
5
48
|
* @param {string} src 路径
|
|
6
49
|
* @returns {string} 位于项目根目录下的位置
|
|
7
|
-
*/export function resolveProgramPath(
|
|
50
|
+
*/ export function resolveProgramPath(src) {
|
|
51
|
+
return resolve(paths.programPath, `./${src}`);
|
|
52
|
+
}
|
|
53
|
+
/** 位于项目根目录node_modules下的位置
|
|
8
54
|
* @param {string} src 路径
|
|
9
55
|
* @returns {string} 位于项目根目录node_modules下的位置
|
|
10
|
-
*/export const resolveNodeModulesPath=
|
|
56
|
+
*/ export const resolveNodeModulesPath = (src)=>{
|
|
57
|
+
return resolveProgramPath(`node_modules/${src}`);
|
|
58
|
+
};
|
|
59
|
+
/** 获取模块真实入口位置
|
|
11
60
|
* @param {string} url 路径
|
|
12
61
|
* @returns {string} 模块真实入口路径
|
|
13
|
-
*/export const realResolve=
|
|
14
|
-
|
|
15
|
-
|
|
62
|
+
*/ export const realResolve = (url)=>resolverSync.resolveSync({}, paths.programPath, url) || url;
|
|
63
|
+
const funcTag = '[object Function]';
|
|
64
|
+
const asyncTag = '[object AsyncFunction]';
|
|
65
|
+
const genTag = '[object GeneratorFunction]';
|
|
66
|
+
const proxyTag = '[object Proxy]';
|
|
67
|
+
export function isObject(target) {
|
|
68
|
+
const type = typeof target;
|
|
69
|
+
return target !== null && (type == 'object' || type == 'function');
|
|
70
|
+
}
|
|
71
|
+
// eslint-disable-next-line no-unused-vars
|
|
72
|
+
export function isFunction(target) {
|
|
73
|
+
if (!isObject(target)) return false;
|
|
74
|
+
const tagType = Object.prototype.toString.call(target);
|
|
75
|
+
return tagType == funcTag || tagType == asyncTag || tagType == genTag || tagType == proxyTag;
|
|
76
|
+
}
|
|
77
|
+
export function empty() {
|
|
78
|
+
// empty void
|
|
79
|
+
}
|
|
@@ -1 +1,49 @@
|
|
|
1
|
-
import
|
|
1
|
+
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
|
2
|
+
import { docs } from './docs.js';
|
|
3
|
+
import { locales, localesModuleName } from './locales.js';
|
|
4
|
+
import { isLibrary } from './process-env.js';
|
|
5
|
+
import { exampleModuleName, examples, route, routesModuleName } from './routes.js';
|
|
6
|
+
import { resolveNodeModulesPath } from './utils.js';
|
|
7
|
+
class VirtualModulePlugin {
|
|
8
|
+
options;
|
|
9
|
+
hasTapped;
|
|
10
|
+
constructor(options){
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.hasTapped = false;
|
|
13
|
+
}
|
|
14
|
+
apply(compiler) {
|
|
15
|
+
const vm = new VirtualModulesPlugin({
|
|
16
|
+
[resolveNodeModulesPath(routesModuleName)]: route.getData(routesModuleName),
|
|
17
|
+
[resolveNodeModulesPath(exampleModuleName)]: 'export default []',
|
|
18
|
+
[resolveNodeModulesPath(localesModuleName)]: locales.getData(localesModuleName)
|
|
19
|
+
});
|
|
20
|
+
vm.apply(compiler);
|
|
21
|
+
function modify(key, value) {
|
|
22
|
+
vm.writeModule(resolveNodeModulesPath(key), value || '');
|
|
23
|
+
}
|
|
24
|
+
route.on('change', modify);
|
|
25
|
+
locales.on('change', modify);
|
|
26
|
+
if (isLibrary) {
|
|
27
|
+
examples.on('change', modify);
|
|
28
|
+
docs.on('change', modify);
|
|
29
|
+
}
|
|
30
|
+
compiler.hooks.compilation.tap('VirtualModulePlugin', ()=>{
|
|
31
|
+
if (!this.hasTapped) {
|
|
32
|
+
for(const key in this.options){
|
|
33
|
+
if (Object.prototype.hasOwnProperty.call(this.options, key)) {
|
|
34
|
+
const value = this.options[key];
|
|
35
|
+
modify(key, typeof value === 'string' ? value : `export default ${JSON.stringify(value)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const item of examples){
|
|
39
|
+
modify(...item);
|
|
40
|
+
}
|
|
41
|
+
for (const item of docs){
|
|
42
|
+
modify(...item);
|
|
43
|
+
}
|
|
44
|
+
this.hasTapped = true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default VirtualModulePlugin;
|
package/lib/virtual-modules.js
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { accessSync, constants } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import appEntry from './app-entry.js';
|
|
4
|
+
import app from './app.js';
|
|
5
|
+
import { CONFIG } from './config.js';
|
|
6
|
+
import { coverage } from './coverage.js';
|
|
7
|
+
import fallback from './fallback.js';
|
|
8
|
+
import mergeRouter from './merge-router.js';
|
|
9
|
+
import normalizeCss from './normalize-css.js';
|
|
10
|
+
import prefixRouter from './prefix-router.js';
|
|
11
|
+
import { FRAMEWORKNAME, isLibrary, isReact } from './process-env.js';
|
|
12
|
+
import { resolveProgramPath } from './utils.js';
|
|
13
|
+
const virtualModules = {
|
|
14
|
+
...CONFIG.virtualModule,
|
|
15
|
+
'@app': app,
|
|
16
|
+
'@app/fallback': fallback,
|
|
17
|
+
'@app/coverage': coverage,
|
|
18
|
+
'@app/normalize/index.css': normalizeCss,
|
|
19
|
+
'@app/prefix-router': prefixRouter,
|
|
20
|
+
'@app/suspense/index.tsx': `import ${isReact ? 'React,' : ''}{Suspense,lazy} from "${FRAMEWORKNAME}";import Fallback from '@app/fallback';${isLibrary ? 'import scope from "@app/mdx-scope";' : ''}function SuspenseComp(props) {const Lazy = lazy(props.comp);return (<Suspense fallback={Fallback && <Fallback />}><Lazy ${isLibrary ? 'components={scope}' : ''}/></Suspense>);}export default SuspenseComp;`,
|
|
21
|
+
'@app/entry': appEntry,
|
|
22
|
+
'@app/merge-router': mergeRouter
|
|
23
|
+
};
|
|
24
|
+
let mdxScope = {};
|
|
25
|
+
if (isLibrary) {
|
|
26
|
+
try {
|
|
27
|
+
const appEntryPath = join(resolveProgramPath('site'), './mdx-scope.ts');
|
|
28
|
+
accessSync(appEntryPath, constants.R_OK);
|
|
29
|
+
mdxScope = 'import scope from "@/mdx-scope";export default scope;';
|
|
30
|
+
} catch (error) {
|
|
31
|
+
mdxScope = {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
Object.assign(virtualModules, {
|
|
35
|
+
'@app/mdx-scope': mdxScope
|
|
36
|
+
});
|
|
37
|
+
export default virtualModules;
|
package/lib/yarn-argv.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const original = JSON.parse(process.env.npm_config_argv || '{}')?.original;
|
|
2
|
+
const yarnArgv = {};
|
|
3
|
+
original?.forEach((o)=>{
|
|
4
|
+
const m = o.split('=');
|
|
5
|
+
Object.assign(yarnArgv, {
|
|
6
|
+
[m[0]]: m[1] || true
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
export default yarnArgv;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.2.1-beta.
|
|
3
|
+
"version": "3.2.1-beta.2",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=
|
|
8
|
+
"build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=false -C jsc.minify.mangle=false -C jsc.minify.compress=false -C minify=false -D",
|
|
9
9
|
"prebuild": "rm -rf ./lib && tsc"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [],
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
"less-loader": "11.1.3",
|
|
31
31
|
"mini-css-extract-plugin": "2.7.6",
|
|
32
32
|
"mini-svg-data-uri": "1.4.4",
|
|
33
|
+
"sass": "1.69.5",
|
|
34
|
+
"sass-loader": "13.3.2",
|
|
33
35
|
"style-loader": "3.3.3",
|
|
34
36
|
"style-resources-loader": "1.5.0",
|
|
35
37
|
"swc-loader": "0.2.3",
|
package/typings/global.d.ts
CHANGED
|
@@ -30,11 +30,10 @@ export type HtmlWebpackOption = HtmlWebpackPluginOptions & {
|
|
|
30
30
|
export type CssMinify = 'swc' | 'cssnano';
|
|
31
31
|
|
|
32
32
|
export type RulesInclude = {
|
|
33
|
-
less?: string[];
|
|
34
33
|
css?: string[];
|
|
35
34
|
js?: string[];
|
|
36
35
|
media?: string[];
|
|
37
|
-
|
|
36
|
+
font?: string[];
|
|
38
37
|
wasm?: string[];
|
|
39
38
|
};
|
|
40
39
|
export interface Theme {
|
package/lib/threads.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/threads.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{Worker as e,isMainThread as r,parentPort as t,workerData as l}from"worker_threads";if(r){// This is the main thread
|
|
2
|
-
let r=Array.from({length:1e6},(e,r)=>r+1),t=r.length/4,l=[],o=0;// Array with 1 million elements
|
|
3
|
-
for(let s=0;s<4;s++){let a=s*t,g=(s+1)*t,n=r.slice(a,g),m=new e(new URL("a.mjs",import.meta.url),{workerData:n});m.on("message",e=>{o+=e,4===l.length&&console.log("Average:",o/r.length)}),l.push(m)}}else t&&t.postMessage(l);
|