@vue3-oop/preset-vue 2.4.14
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/README.md +61 -0
- package/compiled/@vue/babel-plugin-jsx/index.js +33114 -0
- package/compiled/@vue/babel-plugin-jsx/package.json +7 -0
- package/dist/atomParser/index.d.ts +14 -0
- package/dist/atomParser/index.js +115 -0
- package/dist/common.d.ts +3 -0
- package/dist/common.js +57 -0
- package/dist/compiler/browser.d.ts +3 -0
- package/dist/compiler/browser.js +78 -0
- package/dist/compiler/index.d.ts +34 -0
- package/dist/compiler/index.js +208 -0
- package/dist/compiler/node.d.ts +11 -0
- package/dist/compiler/node.js +75 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +59 -0
- package/dist/requireHook.d.ts +2 -0
- package/dist/requireHook.js +67 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.js +64 -0
- package/dist/vue/checkVersion.d.ts +2 -0
- package/dist/vue/checkVersion.js +52 -0
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.js +56 -0
- package/dist/vue/techStack/index.d.ts +2 -0
- package/dist/vue/techStack/index.js +95 -0
- package/dist/vue/techStack/jsx.d.ts +2 -0
- package/dist/vue/techStack/jsx.js +81 -0
- package/dist/vue/techStack/sfc.d.ts +2 -0
- package/dist/vue/techStack/sfc.js +80 -0
- package/dist/vue/webpack/config.d.ts +3 -0
- package/dist/vue/webpack/config.js +85 -0
- package/dist/vue/webpack/index.d.ts +2 -0
- package/dist/vue/webpack/index.js +48 -0
- package/lib/compiler.mjs +73 -0
- package/lib/preflight.mjs +5 -0
- package/lib/renderer.mjs +5 -0
- package/lib/runtimePlugin.mjs +60 -0
- package/package.json +58 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MetaCheckerOptions } from '@dumijs/vue-meta';
|
|
2
|
+
import { IBaseApiParserOptions, ILanguageMetaParser } from 'dumi/tech-stack-utils';
|
|
3
|
+
export interface VueParserOptions extends IBaseApiParserOptions {
|
|
4
|
+
tsconfigPath?: string;
|
|
5
|
+
/**
|
|
6
|
+
* By default, this option is the repository.directory option in package.json
|
|
7
|
+
*
|
|
8
|
+
* Mainly used to change the root directory of parser.
|
|
9
|
+
* The default root directory is obtained through getProjectRoot.
|
|
10
|
+
*/
|
|
11
|
+
directory?: string;
|
|
12
|
+
checkerOptions?: MetaCheckerOptions;
|
|
13
|
+
}
|
|
14
|
+
export declare const VueApiParser: (opts: VueParserOptions) => import("../../../../dist/assetParsers/BaseParser").BaseAtomAssetsParser<ILanguageMetaParser>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/atomParser/index.ts
|
|
30
|
+
var atomParser_exports = {};
|
|
31
|
+
__export(atomParser_exports, {
|
|
32
|
+
VueApiParser: () => VueApiParser
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(atomParser_exports);
|
|
35
|
+
var import_vue_meta = require("@dumijs/vue-meta");
|
|
36
|
+
var import_dumi = require("dumi");
|
|
37
|
+
var import_plugin_utils = require("dumi/plugin-utils");
|
|
38
|
+
var import_tech_stack_utils = require("dumi/tech-stack-utils");
|
|
39
|
+
var import_node_path = __toESM(require("node:path"));
|
|
40
|
+
var VueMetaParser = class {
|
|
41
|
+
entryFile;
|
|
42
|
+
resolveDir;
|
|
43
|
+
checkerOptions;
|
|
44
|
+
checker;
|
|
45
|
+
constructor(opts) {
|
|
46
|
+
const {
|
|
47
|
+
tsconfigPath,
|
|
48
|
+
checkerOptions,
|
|
49
|
+
resolveDir,
|
|
50
|
+
entryFile,
|
|
51
|
+
directory = ""
|
|
52
|
+
} = opts;
|
|
53
|
+
this.checkerOptions = Object.assign(
|
|
54
|
+
{
|
|
55
|
+
// Source link generation is turned off by default, and will provided by dumi
|
|
56
|
+
disableSources: true
|
|
57
|
+
},
|
|
58
|
+
checkerOptions
|
|
59
|
+
);
|
|
60
|
+
this.resolveDir = resolveDir;
|
|
61
|
+
this.entryFile = import_node_path.default.resolve(this.resolveDir, entryFile);
|
|
62
|
+
this.checker = (0, import_vue_meta.createProject)({
|
|
63
|
+
rootPath: import_node_path.default.join((0, import_dumi.getProjectRoot)(resolveDir), directory),
|
|
64
|
+
tsconfigPath,
|
|
65
|
+
checkerOptions: this.checkerOptions
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async patch(file) {
|
|
69
|
+
const { event, fileName } = file;
|
|
70
|
+
switch (event) {
|
|
71
|
+
case "add":
|
|
72
|
+
case "change": {
|
|
73
|
+
const fileContent = await import_plugin_utils.fsExtra.readFile(fileName, "utf8");
|
|
74
|
+
this.checker.patchFiles([
|
|
75
|
+
{ action: event, fileName, text: fileContent }
|
|
76
|
+
]);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
case "unlink":
|
|
80
|
+
this.checker.deleteFile(fileName);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async parse() {
|
|
85
|
+
return this.checker.service.getComponentLibraryMeta(
|
|
86
|
+
this.entryFile,
|
|
87
|
+
import_vue_meta.dumiTransformer
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
async destroy() {
|
|
91
|
+
this.checker.close();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var VueApiParser = (0, import_tech_stack_utils.createApiParser)({
|
|
95
|
+
filename: __filename,
|
|
96
|
+
worker: VueMetaParser,
|
|
97
|
+
parseOptions: {
|
|
98
|
+
handleWatcher(watcher, { parse, patch, watchArgs }) {
|
|
99
|
+
return watcher.on("all", (ev, file) => {
|
|
100
|
+
if (["add", "change", "unlink"].includes(ev) && /((?<!\.d)\.ts|\.(jsx?|tsx|vue))$/.test(file)) {
|
|
101
|
+
const cwd = watchArgs.options.cwd;
|
|
102
|
+
patch({
|
|
103
|
+
event: ev,
|
|
104
|
+
fileName: import_node_path.default.join(cwd, file)
|
|
105
|
+
});
|
|
106
|
+
parse();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
VueApiParser
|
|
115
|
+
});
|
package/dist/common.d.ts
ADDED
package/dist/common.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/common.ts
|
|
20
|
+
var common_exports = {};
|
|
21
|
+
__export(common_exports, {
|
|
22
|
+
default: () => common_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(common_exports);
|
|
25
|
+
var import_atomParser = require("./atomParser");
|
|
26
|
+
var common_default = (api) => {
|
|
27
|
+
api.describe({
|
|
28
|
+
key: "preset-vue:common"
|
|
29
|
+
});
|
|
30
|
+
api.modifyBabelPresetOpts((memo) => {
|
|
31
|
+
memo.presetTypeScript = {
|
|
32
|
+
allExtensions: true,
|
|
33
|
+
isTSX: true
|
|
34
|
+
};
|
|
35
|
+
return memo;
|
|
36
|
+
});
|
|
37
|
+
api.modifyConfig((memo) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const userConfig = api.userConfig;
|
|
40
|
+
const vueConfig = userConfig == null ? void 0 : userConfig.vue;
|
|
41
|
+
const parserOptions = {
|
|
42
|
+
directory: (vueConfig == null ? void 0 : vueConfig.directory) ?? ((_a = api.pkg.repository) == null ? void 0 : _a.directory),
|
|
43
|
+
tsconfigPath: vueConfig == null ? void 0 : vueConfig.tsconfigPath,
|
|
44
|
+
checkerOptions: vueConfig == null ? void 0 : vueConfig.checkerOptions
|
|
45
|
+
};
|
|
46
|
+
const entryFile = (_b = userConfig == null ? void 0 : userConfig.resolve) == null ? void 0 : _b.entryFile;
|
|
47
|
+
const resolveDir = api.cwd;
|
|
48
|
+
const options = {
|
|
49
|
+
entryFile,
|
|
50
|
+
resolveDir
|
|
51
|
+
};
|
|
52
|
+
Object.assign(options, parserOptions);
|
|
53
|
+
if (!options.entryFile || !options.resolveDir) return memo;
|
|
54
|
+
api.service.atomParser = (0, import_atomParser.VueApiParser)(options);
|
|
55
|
+
return memo;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/compiler/browser.ts
|
|
30
|
+
var browser_exports = {};
|
|
31
|
+
__export(browser_exports, {
|
|
32
|
+
default: () => compile
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(browser_exports);
|
|
35
|
+
var import_babel_plugin_jsx = __toESM(require("@vue/babel-plugin-jsx"));
|
|
36
|
+
var import_hash_sum = __toESM(require("hash-sum"));
|
|
37
|
+
var import_index = require("./index");
|
|
38
|
+
var { compileSFC, transformTS, toCommonJS } = (0, import_index.createCompiler)({
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
typescript: () => window.ts,
|
|
41
|
+
babel: {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
transformSync(...args) {
|
|
44
|
+
if (typeof window !== void 0 && "Babel" in window) {
|
|
45
|
+
return Babel.transform(...args);
|
|
46
|
+
}
|
|
47
|
+
console.error("@babel/standablone is loading!");
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
availablePlugins: {
|
|
52
|
+
"vue-jsx": import_babel_plugin_jsx.default
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
function compile(code, { filename }) {
|
|
56
|
+
var _a;
|
|
57
|
+
const { lang } = (0, import_index.resolveFilename)(filename);
|
|
58
|
+
if (["js", "jsx", "ts", "tsx"].includes(lang)) {
|
|
59
|
+
return transformTS(code, filename, {
|
|
60
|
+
lang,
|
|
61
|
+
presets: [["env", { modules: "cjs" }]]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const id = (0, import_hash_sum.default)(filename);
|
|
65
|
+
const compiled = compileSFC({ id, filename, code });
|
|
66
|
+
if (Array.isArray(compiled)) {
|
|
67
|
+
throw compiled[0];
|
|
68
|
+
}
|
|
69
|
+
let { js, css } = compiled;
|
|
70
|
+
if (css) {
|
|
71
|
+
js += `
|
|
72
|
+
${import_index.COMP_IDENTIFIER}.__css__ = ${JSON.stringify(css)};`;
|
|
73
|
+
}
|
|
74
|
+
js += `
|
|
75
|
+
${import_index.COMP_IDENTIFIER}.__id__ = "${id}";
|
|
76
|
+
export default ${import_index.COMP_IDENTIFIER};`;
|
|
77
|
+
return ((_a = toCommonJS(js)) == null ? void 0 : _a.code) || "";
|
|
78
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BabelCore, babelCore } from 'dumi/tech-stack-utils';
|
|
2
|
+
import type * as typescript from 'typescript';
|
|
3
|
+
import { CompilerError } from 'vue/compiler-sfc';
|
|
4
|
+
export interface CompileOptions {
|
|
5
|
+
id: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
code: string;
|
|
8
|
+
}
|
|
9
|
+
export type CompileResult = (string | CompilerError | SyntaxError)[] | {
|
|
10
|
+
js: string;
|
|
11
|
+
css: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveFilename(filename: string): {
|
|
14
|
+
basename: string;
|
|
15
|
+
lang: string;
|
|
16
|
+
};
|
|
17
|
+
type Plugins = Record<string, BabelCore.PluginItem>;
|
|
18
|
+
type CreateCompilerContext = {
|
|
19
|
+
typescript: () => typeof typescript;
|
|
20
|
+
babel: ReturnType<typeof babelCore>;
|
|
21
|
+
availablePlugins?: Plugins;
|
|
22
|
+
availablePresets?: Plugins;
|
|
23
|
+
};
|
|
24
|
+
export declare const COMP_IDENTIFIER = "__sfc__";
|
|
25
|
+
export declare function createCompiler({ typescript, babel, availablePlugins, availablePresets, }: CreateCompilerContext): {
|
|
26
|
+
toCommonJS: (es: string) => BabelCore.BabelFileResult | null;
|
|
27
|
+
transformTS: (src: string, filename: string, options?: {
|
|
28
|
+
lang?: string;
|
|
29
|
+
plugins?: BabelCore.PluginItem[];
|
|
30
|
+
presets?: BabelCore.PluginItem[];
|
|
31
|
+
}) => string;
|
|
32
|
+
compileSFC: (options: CompileOptions) => CompileResult;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/compiler/index.ts
|
|
20
|
+
var compiler_exports = {};
|
|
21
|
+
__export(compiler_exports, {
|
|
22
|
+
COMP_IDENTIFIER: () => COMP_IDENTIFIER,
|
|
23
|
+
createCompiler: () => createCompiler,
|
|
24
|
+
resolveFilename: () => resolveFilename
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(compiler_exports);
|
|
27
|
+
var import_compiler_sfc = require("vue/compiler-sfc");
|
|
28
|
+
function resolveFilename(filename) {
|
|
29
|
+
const [, basename, lang] = filename.match(/([^.]+)\.([^.]+)$/) || [];
|
|
30
|
+
return { basename, lang };
|
|
31
|
+
}
|
|
32
|
+
var COMP_IDENTIFIER = "__sfc__";
|
|
33
|
+
function createCompiler({
|
|
34
|
+
typescript,
|
|
35
|
+
babel,
|
|
36
|
+
availablePlugins = {},
|
|
37
|
+
availablePresets = {}
|
|
38
|
+
}) {
|
|
39
|
+
function toCommonJS(es) {
|
|
40
|
+
return babel.transformSync(es, {
|
|
41
|
+
presets: [[availablePresets["env"] ?? "env", { modules: "cjs" }]]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function transformTS(src, filename, options = {}) {
|
|
45
|
+
const { lang, plugins = [], presets = [] } = options;
|
|
46
|
+
if (lang === "ts" || lang === "tsx") {
|
|
47
|
+
const isTSX = lang === "tsx";
|
|
48
|
+
presets.push([
|
|
49
|
+
availablePresets["typescript"] ?? "typescript",
|
|
50
|
+
{ isTSX, allExtensions: isTSX, onlyRemoveTypeImports: true }
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
if (lang === "tsx" || lang === "jsx") {
|
|
54
|
+
plugins.push(availablePlugins["vue-jsx"] ?? "vue-jsx");
|
|
55
|
+
}
|
|
56
|
+
const { basename } = resolveFilename(filename);
|
|
57
|
+
let code = src;
|
|
58
|
+
if ((lang === "ts" || lang === "tsx") && typescript()) {
|
|
59
|
+
const ts = typescript();
|
|
60
|
+
const { outputText } = ts.transpileModule(src, {
|
|
61
|
+
compilerOptions: {
|
|
62
|
+
module: ts.ModuleKind.ESNext,
|
|
63
|
+
target: ts.ScriptTarget.ES2020,
|
|
64
|
+
jsx: ts.JsxEmit.Preserve,
|
|
65
|
+
jsxImportSource: "vue",
|
|
66
|
+
isolatedModules: true,
|
|
67
|
+
experimentalDecorators: true,
|
|
68
|
+
emitDecoratorMetadata: true,
|
|
69
|
+
useDefineForClassFields: false,
|
|
70
|
+
verbatimModuleSyntax: true,
|
|
71
|
+
inlineSourceMap: true
|
|
72
|
+
},
|
|
73
|
+
fileName: basename + "." + (lang || "ts"),
|
|
74
|
+
reportDiagnostics: true
|
|
75
|
+
});
|
|
76
|
+
code = outputText;
|
|
77
|
+
}
|
|
78
|
+
const result = babel.transformSync(code, {
|
|
79
|
+
filename: basename + "." + (lang || "ts"),
|
|
80
|
+
presets,
|
|
81
|
+
plugins
|
|
82
|
+
});
|
|
83
|
+
return (result == null ? void 0 : result.code) || "";
|
|
84
|
+
}
|
|
85
|
+
function doCompileScript(id, descriptor, hasScoped, lang) {
|
|
86
|
+
const { filename, template, scriptSetup, script } = descriptor;
|
|
87
|
+
const templateContent = template == null ? void 0 : template.content;
|
|
88
|
+
const hasSetup = !!scriptSetup;
|
|
89
|
+
const isTS = lang === "ts" || lang === "tsx";
|
|
90
|
+
const expressionPlugins = [];
|
|
91
|
+
if (isTS) expressionPlugins.push("typescript");
|
|
92
|
+
if (lang === "jsx" || lang === "tsx") expressionPlugins.push("jsx");
|
|
93
|
+
let sfcCode = "";
|
|
94
|
+
if (script || scriptSetup) {
|
|
95
|
+
try {
|
|
96
|
+
const { content } = (0, import_compiler_sfc.compileScript)(descriptor, {
|
|
97
|
+
id,
|
|
98
|
+
inlineTemplate: hasSetup,
|
|
99
|
+
templateOptions: {
|
|
100
|
+
compilerOptions: { expressionPlugins }
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
sfcCode = transformTS(
|
|
104
|
+
(0, import_compiler_sfc.rewriteDefault)(content, COMP_IDENTIFIER, expressionPlugins),
|
|
105
|
+
filename,
|
|
106
|
+
{ lang }
|
|
107
|
+
);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return [error];
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
sfcCode = `const ${COMP_IDENTIFIER} = {};`;
|
|
113
|
+
}
|
|
114
|
+
if (!hasSetup && templateContent) {
|
|
115
|
+
let { code, errors } = (0, import_compiler_sfc.compileTemplate)({
|
|
116
|
+
id,
|
|
117
|
+
filename,
|
|
118
|
+
source: templateContent,
|
|
119
|
+
scoped: hasScoped,
|
|
120
|
+
compilerOptions: { expressionPlugins }
|
|
121
|
+
});
|
|
122
|
+
if (errors.length) {
|
|
123
|
+
return errors;
|
|
124
|
+
}
|
|
125
|
+
code = transformTS(code, filename, { lang });
|
|
126
|
+
sfcCode += `
|
|
127
|
+
${code.replace(
|
|
128
|
+
/\nexport (function|const) render/,
|
|
129
|
+
`$1 render`
|
|
130
|
+
)}
|
|
131
|
+
${COMP_IDENTIFIER}.render = render;`;
|
|
132
|
+
}
|
|
133
|
+
return sfcCode;
|
|
134
|
+
}
|
|
135
|
+
function doCompileStyle(id, descriptor) {
|
|
136
|
+
const { filename } = descriptor;
|
|
137
|
+
const styleList = [];
|
|
138
|
+
for (const style of descriptor.styles) {
|
|
139
|
+
const { code, errors } = (0, import_compiler_sfc.compileStyle)({
|
|
140
|
+
source: style.content,
|
|
141
|
+
filename,
|
|
142
|
+
id,
|
|
143
|
+
scoped: style.scoped
|
|
144
|
+
});
|
|
145
|
+
if (errors.length) {
|
|
146
|
+
return errors;
|
|
147
|
+
}
|
|
148
|
+
styleList.push(code);
|
|
149
|
+
}
|
|
150
|
+
return styleList.join("\n");
|
|
151
|
+
}
|
|
152
|
+
function compileSFC(options) {
|
|
153
|
+
const { id, code, filename } = options;
|
|
154
|
+
const { descriptor, errors } = (0, import_compiler_sfc.parse)(code, { filename });
|
|
155
|
+
if (errors.length) {
|
|
156
|
+
return errors;
|
|
157
|
+
}
|
|
158
|
+
let js = "";
|
|
159
|
+
let skipStyleCompile = false;
|
|
160
|
+
if (descriptor.styles.some((style) => style.lang) || descriptor.template && descriptor.template.lang) {
|
|
161
|
+
skipStyleCompile = true;
|
|
162
|
+
js += '\nconsole.warn("Custom preprocessors for <template> and <style> are not supported in the Codeblock.")';
|
|
163
|
+
}
|
|
164
|
+
if (descriptor.styles.some((style) => style.module)) {
|
|
165
|
+
skipStyleCompile = true;
|
|
166
|
+
js += '\nconsole.warn("<style module> is not supported in the the Codeblock.")';
|
|
167
|
+
}
|
|
168
|
+
const scriptLang = descriptor.script && descriptor.script.lang || descriptor.scriptSetup && descriptor.scriptSetup.lang;
|
|
169
|
+
const hasScoped = descriptor.styles.some((style) => style.scoped);
|
|
170
|
+
const scriptResult = doCompileScript(
|
|
171
|
+
id,
|
|
172
|
+
descriptor,
|
|
173
|
+
hasScoped,
|
|
174
|
+
scriptLang || ""
|
|
175
|
+
);
|
|
176
|
+
if (Array.isArray(scriptResult)) {
|
|
177
|
+
return scriptResult;
|
|
178
|
+
}
|
|
179
|
+
js += `
|
|
180
|
+
${scriptResult}`;
|
|
181
|
+
if (hasScoped) {
|
|
182
|
+
js += `
|
|
183
|
+
${COMP_IDENTIFIER}.__scopeId = ${JSON.stringify(
|
|
184
|
+
`data-v-${id}`
|
|
185
|
+
)};`;
|
|
186
|
+
}
|
|
187
|
+
let css = "";
|
|
188
|
+
if (!skipStyleCompile) {
|
|
189
|
+
const styleResult = doCompileStyle(id, descriptor);
|
|
190
|
+
if (Array.isArray(styleResult)) {
|
|
191
|
+
return styleResult;
|
|
192
|
+
}
|
|
193
|
+
css = styleResult;
|
|
194
|
+
}
|
|
195
|
+
return { js, css };
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
toCommonJS,
|
|
199
|
+
transformTS,
|
|
200
|
+
compileSFC
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
COMP_IDENTIFIER,
|
|
206
|
+
createCompiler,
|
|
207
|
+
resolveFilename
|
|
208
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CompileOptions } from './index';
|
|
2
|
+
export declare const compiler: {
|
|
3
|
+
toCommonJS: (es: string) => import("@umijs/bundler-utils/compiled/@babel/core").BabelFileResult | null;
|
|
4
|
+
transformTS: (src: string, filename: string, options?: {
|
|
5
|
+
lang?: string | undefined;
|
|
6
|
+
plugins?: import("@umijs/bundler-utils/compiled/@babel/core").PluginItem[] | undefined;
|
|
7
|
+
presets?: import("@umijs/bundler-utils/compiled/@babel/core").PluginItem[] | undefined;
|
|
8
|
+
}) => string;
|
|
9
|
+
compileSFC: (options: CompileOptions) => import("./index").CompileResult;
|
|
10
|
+
};
|
|
11
|
+
export declare function compile(options: CompileOptions): string | (string | import("vue/compiler-sfc").CompilerError | SyntaxError)[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/compiler/node.ts
|
|
30
|
+
var node_exports = {};
|
|
31
|
+
__export(node_exports, {
|
|
32
|
+
compile: () => compile,
|
|
33
|
+
compiler: () => compiler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(node_exports);
|
|
36
|
+
var import_tech_stack_utils = require("dumi/tech-stack-utils");
|
|
37
|
+
var ts = __toESM(require("typescript"));
|
|
38
|
+
var import_index = require("./index");
|
|
39
|
+
var babel = (0, import_tech_stack_utils.babelCore)();
|
|
40
|
+
var env = (0, import_tech_stack_utils.babelPresetEnv)();
|
|
41
|
+
var typescript = (0, import_tech_stack_utils.babelPresetTypeScript)();
|
|
42
|
+
var compiler = (0, import_index.createCompiler)({
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
typescript: () => globalThis.supportTsMetadata && ts,
|
|
45
|
+
babel,
|
|
46
|
+
availablePlugins: {
|
|
47
|
+
"vue-jsx": require.resolve("../../compiled/@vue/babel-plugin-jsx")
|
|
48
|
+
},
|
|
49
|
+
availablePresets: { env, typescript }
|
|
50
|
+
});
|
|
51
|
+
function compile(options) {
|
|
52
|
+
const { id, filename, code } = options;
|
|
53
|
+
const [, lang] = filename.match(/[^.]+\.([^.]+)$/) || [];
|
|
54
|
+
if (["js", "jsx", "ts", "tsx"].includes(lang)) {
|
|
55
|
+
return compiler.transformTS(code, filename, { lang });
|
|
56
|
+
}
|
|
57
|
+
const compiled = compiler.compileSFC(options);
|
|
58
|
+
if (Array.isArray(compiled)) {
|
|
59
|
+
return compiled;
|
|
60
|
+
}
|
|
61
|
+
let { js, css } = compiled;
|
|
62
|
+
if (css) {
|
|
63
|
+
js += `
|
|
64
|
+
${import_index.COMP_IDENTIFIER}.__css__ = ${JSON.stringify(css)};`;
|
|
65
|
+
}
|
|
66
|
+
js += `
|
|
67
|
+
${import_index.COMP_IDENTIFIER}.__id__ = "${id}";
|
|
68
|
+
export default ${import_index.COMP_IDENTIFIER};`;
|
|
69
|
+
return js;
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
compile,
|
|
74
|
+
compiler
|
|
75
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_types = require("@umijs/core/dist/types");
|
|
36
|
+
var import_requireHook = require("./requireHook");
|
|
37
|
+
var src_default = (api) => {
|
|
38
|
+
api.describe({
|
|
39
|
+
key: "vue",
|
|
40
|
+
config: {
|
|
41
|
+
schema({ zod }) {
|
|
42
|
+
return zod.object({
|
|
43
|
+
directory: zod.string().optional(),
|
|
44
|
+
tsconfigPath: zod.string().optional(),
|
|
45
|
+
supportTsMetadata: zod.boolean().optional(),
|
|
46
|
+
checkerOptions: zod.object({}).optional(),
|
|
47
|
+
compiler: zod.object({
|
|
48
|
+
babelStandaloneCDN: zod.string().optional(),
|
|
49
|
+
typescriptCDN: zod.string().optional()
|
|
50
|
+
}).optional()
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
enableBy: import_types.EnableBy.config
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
plugins: [require.resolve("./common"), require.resolve("./vue")]
|
|
58
|
+
};
|
|
59
|
+
};
|