@spcsn/taro-helper 0.1.0

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/dist/dotenv.js ADDED
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.patchEnv = exports.dotenvParse = exports.formatPrefix = void 0;
37
+ const path = __importStar(require("node:path"));
38
+ const dotenv_1 = require("dotenv");
39
+ const dotenv_expand_1 = require("dotenv-expand");
40
+ const fs = __importStar(require("fs-extra"));
41
+ // 支持 --env-prefix=TARO_APP_,aa 类型参数
42
+ const formatPrefix = (prefixs = ['TARO_APP_']) => {
43
+ const prefixsArr = (Array.isArray(prefixs) ? prefixs : prefixs.split(','))
44
+ .map((prefix) => prefix.trim())
45
+ .filter((prefix) => !!prefix);
46
+ return prefixsArr;
47
+ };
48
+ exports.formatPrefix = formatPrefix;
49
+ const dotenvParse = (root, prefixs = ['TARO_APP_'], mode) => {
50
+ const prefixsArr = (0, exports.formatPrefix)(prefixs);
51
+ const envFiles = new Set([/** default file */ `.env`, /** local file */ `.env.local`]);
52
+ if (mode) {
53
+ envFiles.add(/** mode file */ `.env.${mode}`);
54
+ envFiles.add(/** mode local file */ `.env.${mode}.local`);
55
+ }
56
+ let parseTemp = {};
57
+ const load = (envPath) => {
58
+ // file doesn'et exist
59
+ if (!fs.existsSync(envPath))
60
+ return;
61
+ const env = (0, dotenv_1.parse)(fs.readFileSync(envPath));
62
+ parseTemp = {
63
+ ...parseTemp,
64
+ ...env,
65
+ };
66
+ };
67
+ envFiles.forEach((envPath) => {
68
+ load(path.resolve(root, envPath));
69
+ });
70
+ const parsed = {};
71
+ Object.entries(parseTemp).forEach(([key, value]) => {
72
+ if (prefixsArr.some((prefix) => key.startsWith(prefix)) || ['TARO_APP_ID'].includes(key)) {
73
+ parsed[key] = value;
74
+ }
75
+ });
76
+ (0, dotenv_expand_1.expand)({ parsed });
77
+ return parsed;
78
+ };
79
+ exports.dotenvParse = dotenvParse;
80
+ // 扩展 env
81
+ const patchEnv = (config, expandEnv) => {
82
+ const expandEnvStringify = {};
83
+ for (const key in expandEnv) {
84
+ expandEnvStringify[key] = JSON.stringify(expandEnv[key]);
85
+ }
86
+ return {
87
+ ...config.env,
88
+ ...expandEnvStringify,
89
+ };
90
+ };
91
+ exports.patchEnv = patchEnv;
92
+ //# sourceMappingURL=dotenv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotenv.js","sourceRoot":"","sources":["../src/dotenv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AA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uild';
4
+ export declare const defaultEsbuildLoader: Record<string, Loader>;
5
+ export interface IRequireWithEsbuildOptions {
6
+ customConfig?: Parameters<typeof esbuild.build>[0];
7
+ customSwcConfig?: Config;
8
+ cwd?: string;
9
+ }
10
+ /** 基于 esbuild 的 require 实现 */
11
+ export declare function requireWithEsbuild(id: string, { customConfig, customSwcConfig, cwd }?: IRequireWithEsbuildOptions): any;
12
+ export { esbuild };
13
+ export * from './utils';
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.esbuild = exports.defaultEsbuildLoader = void 0;
21
+ exports.requireWithEsbuild = requireWithEsbuild;
22
+ const core_1 = require("@swc/core");
23
+ const esbuild_1 = __importDefault(require("esbuild"));
24
+ exports.esbuild = esbuild_1.default;
25
+ const lodash_1 = require("lodash");
26
+ const require_from_string_1 = __importDefault(require("require-from-string"));
27
+ const constants_1 = require("../constants");
28
+ exports.defaultEsbuildLoader = {
29
+ '.js': 'js',
30
+ '.jsx': 'tsx',
31
+ '.ts': 'ts',
32
+ '.json': 'json',
33
+ };
34
+ /** 基于 esbuild 的 require 实现 */
35
+ function requireWithEsbuild(id, { customConfig = {}, customSwcConfig = {}, cwd = process.cwd() } = {}) {
36
+ const { outputFiles = [] } = esbuild_1.default.buildSync((0, lodash_1.defaults)((0, lodash_1.omit)(customConfig, ['alias', 'define', 'loader', 'plugins']), {
37
+ platform: 'node',
38
+ absWorkingDir: cwd,
39
+ bundle: true,
40
+ define: (0, lodash_1.defaults)(customConfig.define, {
41
+ // AMD 被 esbuild 转 ESM 后,是套着 ESM 外皮的 AMD 语法模块。
42
+ // Webpack HarmonyDetectionParserPlugin 会阻止 AMDDefineDependencyParserPlugin 对这些模块的处理。
43
+ // 导致这些模块报错(如 lodash)。目前的办法是把 define 置为 false,不支持 AMD 导出。
44
+ define: 'false',
45
+ }),
46
+ alias: Object.fromEntries(Object.entries(customConfig.alias || {}).filter(([key]) => !key.startsWith('/'))),
47
+ entryPoints: [id],
48
+ format: 'esm',
49
+ loader: (0, lodash_1.defaults)(customConfig.loader, exports.defaultEsbuildLoader),
50
+ mainFields: [...constants_1.defaultMainFields],
51
+ write: false,
52
+ }));
53
+ // Note: esbuild.buildSync 模式下不支持引入插件,所以这里需要手动转换
54
+ const { code = '' } = (0, core_1.transformSync)(outputFiles[0].text, (0, lodash_1.defaults)(customSwcConfig, {
55
+ jsc: { target: 'es2015' },
56
+ }));
57
+ return (0, require_from_string_1.default)(code, id);
58
+ }
59
+ __exportStar(require("./utils"), exports);
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/esbuild/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,gDAgCC;AAvDD,oCAAkD;AAClD,sDAA8B;AAwDrB,kBAxDF,iBAAO,CAwDE;AAvDhB,mCAAwC;AACxC,8EAAoD;AAEpD,4CAAiD;AAIpC,QAAA,oBAAoB,GAA2B;IAC1D,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,MAAM;CA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1B,CAAC,CACH,CAAC;IACF,OAAO,IAAA,6BAAiB,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC;AAGD,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ import type { Config } from '@swc/core';
2
+ import type { Plugin } from 'esbuild';
3
+ export declare function getSwcPlugin(config?: Config): Plugin;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSwcPlugin = getSwcPlugin;
4
+ const node_path_1 = require("node:path");
5
+ const core_1 = require("@swc/core");
6
+ const lodash_1 = require("lodash");
7
+ const constants_1 = require("../constants");
8
+ const utils_1 = require("../utils");
9
+ function getSwcPlugin(config) {
10
+ return {
11
+ name: 'swc-plugin',
12
+ setup(build) {
13
+ const namespace = 'tarojs:swc-helper';
14
+ build.onResolve({ filter: constants_1.REG_SCRIPTS, namespace }, ({ resolveDir, path }) => ({
15
+ path: (0, node_path_1.resolve)(resolveDir, path),
16
+ }));
17
+ build.onLoad({ filter: constants_1.REG_SCRIPTS, namespace }, async ({ path }) => {
18
+ const code = await utils_1.fs.readFile(path, 'utf-8');
19
+ const result = (0, core_1.transformSync)(code, (0, lodash_1.defaults)(config, {
20
+ jsc: { target: 'es2015' },
21
+ filename: path,
22
+ sourceMaps: true,
23
+ sourceFileName: path,
24
+ }));
25
+ return {
26
+ contents: result.code,
27
+ loader: 'js',
28
+ };
29
+ });
30
+ },
31
+ };
32
+ }
33
+ //# sourceMappingURL=swc-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swc-plugin.js","sourceRoot":"","sources":["../../src/esbuild/swc-plugin.ts"],"names":[],"mappings":";;AAWA,oCA4BC;AAvCD,yCAAoC;AAEpC,oCAA0C;AAC1C,mCAAkC;AAElC,4CAA2C;AAC3C,oCAA8B;AAK9B,SAAgB,YAAY,CAAC,MAAe;IAC1C,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,KAAK,CAAC,KAAK;YACT,MAAM,SAAS,GAAG,mBAAmB,CAAC;YACtC,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,uBAAW,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7E,IAAI,EAAE,IAAA,mBAAO,EAAC,UAAU,EAAE,IAAI,CAAC;aAChC,CAAC,CAAC,CAAC;YAEJ,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,uBAAW,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;gBAClE,MAAM,IAAI,GAAG,MAAM,UAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC9C,MAAM,MAAM,GAAW,IAAA,oBAAa,EAClC,IAAI,EACJ,IAAA,iBAAQ,EAAC,MAAM,EAAE;oBACf,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;oBACzB,QAAQ,EAAE,IAAI;oBACd,UAAU,EAAE,IAAI;oBAChB,cAAc,EAAE,IAAI;iBACrB,CAAC,CACH,CAAC;gBAEF,OAAO;oBACL,QAAQ,EAAE,MAAM,CAAC,IAAI;oBACrB,MAAM,EAAE,IAAI;iBACb,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { OnResolveArgs, OnResolveResult } from 'esbuild';
2
+ export declare function externalEsbuildModule({ path, namespace, importer, pluginData, }: Partial<OnResolveArgs>): OnResolveResult;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.externalEsbuildModule = externalEsbuildModule;
4
+ const node_path_1 = require("node:path");
5
+ function externalEsbuildModule({ path, namespace, importer, pluginData, }) {
6
+ if (namespace === 'file' && importer && path) {
7
+ path = (0, node_path_1.resolve)(importer, path);
8
+ }
9
+ return {
10
+ path,
11
+ namespace,
12
+ pluginData,
13
+ external: true,
14
+ };
15
+ }
16
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/esbuild/utils.ts"],"names":[],"mappings":";;AAIA,sDAeC;AAnBD,yCAAoC;AAIpC,SAAgB,qBAAqB,CAAC,EACpC,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,UAAU,GACa;IACvB,IAAI,SAAS,KAAK,MAAM,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QAC7C,IAAI,GAAG,IAAA,mBAAO,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,OAAO;QACL,IAAI;QACJ,SAAS;QACT,UAAU;QACV,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ export * as swc from '@swc/core';
2
+ export * as chokidar from 'chokidar';
3
+ export declare const createDebug: (id: string) => any;
4
+ export { injectDefineConfigHeader } from './babelRegister';
5
+ export * from './constants';
6
+ export * from './dotenv';
7
+ export * from './esbuild';
8
+ export * as npm from './npm';
9
+ export { default as createSwcRegister } from './swcRegister';
10
+ export * from './terminal';
11
+ export * from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.createSwcRegister = exports.npm = exports.injectDefineConfigHeader = exports.createDebug = exports.chokidar = exports.swc = void 0;
43
+ exports.swc = __importStar(require("@swc/core"));
44
+ exports.chokidar = __importStar(require("chokidar"));
45
+ const createDebug = (id) => require('debug')(id);
46
+ exports.createDebug = createDebug;
47
+ var babelRegister_1 = require("./babelRegister");
48
+ Object.defineProperty(exports, "injectDefineConfigHeader", { enumerable: true, get: function () { return babelRegister_1.injectDefineConfigHeader; } });
49
+ __exportStar(require("./constants"), exports);
50
+ __exportStar(require("./dotenv"), exports);
51
+ __exportStar(require("./esbuild"), exports);
52
+ exports.npm = __importStar(require("./npm"));
53
+ var swcRegister_1 = require("./swcRegister");
54
+ Object.defineProperty(exports, "createSwcRegister", { enumerable: true, get: function () { return __importDefault(swcRegister_1).default; } });
55
+ __exportStar(require("./terminal"), exports);
56
+ __exportStar(require("./utils"), exports);
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAiC;AACjC,qDAAqC;AAE9B,MAAM,WAAW,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;AAAnD,QAAA,WAAW,eAAwC;AAEhE,iDAA2D;AAAlD,yHAAA,wBAAwB,OAAA;AACjC,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA6B;AAC7B,6CAA6D;AAApD,iIAAA,OAAO,OAAqB;AACrC,6CAA2B;AAC3B,0CAAwB"}
package/dist/npm.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ type pluginFunction = (pluginName: string, content: string | null, file: string, config: Record<string, any>, root: string) => any;
2
+ export interface IInstallOptions {
3
+ dev: boolean;
4
+ peerDependencies?: boolean;
5
+ }
6
+ export declare const taroPluginPrefix = "@spcsn/taro-plugin-";
7
+ export declare function resolveNpm(pluginName: string, root?: string): Promise<string>;
8
+ export declare function resolveNpmSync(pluginName: string, root?: string): string;
9
+ export declare function installNpmPkg(pkgList: string[] | string, options: IInstallOptions): any;
10
+ export declare const callPlugin: pluginFunction;
11
+ export declare const callPluginSync: pluginFunction;
12
+ export declare function getNpmPkgSync(npmName: string, root: string): any;
13
+ export declare function getNpmPkg(npmName: string, root: string): Promise<any>;
14
+ export {};
package/dist/npm.js ADDED
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.callPluginSync = exports.callPlugin = exports.taroPluginPrefix = void 0;
37
+ exports.resolveNpm = resolveNpm;
38
+ exports.resolveNpmSync = resolveNpmSync;
39
+ exports.installNpmPkg = installNpmPkg;
40
+ exports.getNpmPkgSync = getNpmPkgSync;
41
+ exports.getNpmPkg = getNpmPkg;
42
+ const Util = __importStar(require("./utils"));
43
+ const PEERS = /UNMET PEER DEPENDENCY ([a-z\-0-9.]+)@(.+)/gm;
44
+ const npmCached = {};
45
+ const erroneous = [];
46
+ const defaultInstallOptions = {
47
+ dev: false,
48
+ peerDependencies: true,
49
+ };
50
+ exports.taroPluginPrefix = '@spcsn/taro-plugin-';
51
+ function resolveNpm(pluginName, root) {
52
+ const resolvePath = require('resolve');
53
+ if (!npmCached[pluginName]) {
54
+ return new Promise((resolve, reject) => {
55
+ resolvePath(`${pluginName}`, { basedir: root }, (err, res) => {
56
+ if (err && err.code === 'MODULE_NOT_FOUND') {
57
+ try {
58
+ const cliPath = require.resolve('@spcsn/taro-cli/package.json', {
59
+ paths: [__dirname, root].filter(Boolean),
60
+ });
61
+ const res = resolvePath.sync(pluginName, { basedir: require('path').dirname(cliPath) });
62
+ if (res) {
63
+ npmCached[pluginName] = res;
64
+ resolve(res);
65
+ return;
66
+ }
67
+ }
68
+ catch (e2) {
69
+ console.error('!!! FATAL e2 !!!', e2);
70
+ throw e2;
71
+ }
72
+ resolvePath(`${pluginName}`, { basedir: __dirname }, (err2, res2) => {
73
+ if (err2)
74
+ return reject(err2);
75
+ npmCached[pluginName] = res2;
76
+ resolve(res2 || '');
77
+ });
78
+ return;
79
+ }
80
+ if (err) {
81
+ return reject(err);
82
+ }
83
+ npmCached[pluginName] = res;
84
+ resolve(res || '');
85
+ });
86
+ });
87
+ }
88
+ return Promise.resolve(npmCached[pluginName]);
89
+ }
90
+ function resolveNpmSync(pluginName, root) {
91
+ const resolvePath = require('resolve');
92
+ try {
93
+ if (!npmCached[pluginName]) {
94
+ let res;
95
+ try {
96
+ res = resolvePath.sync(pluginName, { basedir: root });
97
+ }
98
+ catch (e) {
99
+ if (e.code === 'MODULE_NOT_FOUND') {
100
+ try {
101
+ const cliPath = require.resolve('@spcsn/taro-cli/package.json', {
102
+ paths: [__dirname, root].filter(Boolean),
103
+ });
104
+ return resolvePath.sync(pluginName, { basedir: require('path').dirname(cliPath) });
105
+ }
106
+ catch (e2) {
107
+ console.error('RESOLVE_FAILED', String(e2));
108
+ }
109
+ try {
110
+ const cliPath = require.resolve('@spcsn/taro-cli/package.json', {
111
+ paths: [__dirname, root].filter(Boolean),
112
+ });
113
+ return resolvePath.sync(pluginName, { basedir: require('path').dirname(cliPath) });
114
+ }
115
+ catch (e2) {
116
+ console.error('RESOLVE_FAILED', String(e2));
117
+ }
118
+ res = resolvePath.sync(pluginName, { basedir: __dirname });
119
+ }
120
+ else {
121
+ throw e;
122
+ }
123
+ }
124
+ return res;
125
+ }
126
+ return npmCached[pluginName];
127
+ }
128
+ catch (err) {
129
+ if (err.code === 'MODULE_NOT_FOUND') {
130
+ console.error('!!! CAUGHT FATAL !!!', err, err.stack);
131
+ const installOptions = {
132
+ dev: false,
133
+ };
134
+ if (pluginName.indexOf(exports.taroPluginPrefix) >= 0) {
135
+ installOptions.dev = true;
136
+ }
137
+ installNpmPkg(pluginName, installOptions);
138
+ return resolveNpmSync(pluginName, root);
139
+ }
140
+ return '';
141
+ }
142
+ }
143
+ function installNpmPkg(pkgList, options) {
144
+ if (!pkgList) {
145
+ return;
146
+ }
147
+ if (!Array.isArray(pkgList)) {
148
+ pkgList = [pkgList];
149
+ }
150
+ pkgList = pkgList.filter((dep) => {
151
+ return erroneous.indexOf(dep) === -1;
152
+ });
153
+ if (!pkgList.length) {
154
+ return;
155
+ }
156
+ options = Object.assign({}, defaultInstallOptions, options);
157
+ let installer = '';
158
+ let args = [];
159
+ if (Util.shouldUseYarn()) {
160
+ installer = 'yarn';
161
+ }
162
+ else if (Util.shouldUseCnpm()) {
163
+ installer = 'cnpm';
164
+ }
165
+ else {
166
+ installer = 'npm';
167
+ }
168
+ if (Util.shouldUseYarn()) {
169
+ args = ['add'].concat(pkgList).filter(Boolean);
170
+ args.push('--silent', '--no-progress');
171
+ if (options.dev) {
172
+ args.push('-D');
173
+ }
174
+ }
175
+ else {
176
+ args = ['install'].concat(pkgList).filter(Boolean);
177
+ args.push('--silent', '--no-progress');
178
+ if (options.dev) {
179
+ args.push('--save-dev');
180
+ }
181
+ else {
182
+ args.push('--save');
183
+ }
184
+ }
185
+ const spawn = require('cross-spawn');
186
+ const output = spawn.sync(installer, args, {
187
+ stdio: ['ignore', 'pipe', 'inherit'],
188
+ });
189
+ if (output.status) {
190
+ pkgList.forEach((dep) => {
191
+ erroneous.push(dep);
192
+ });
193
+ }
194
+ let matches = null;
195
+ const peers = [];
196
+ while ((matches = PEERS.exec(output.stdout))) {
197
+ const pkg = matches[1];
198
+ const version = matches[2];
199
+ if (version.match(' ')) {
200
+ peers.push(pkg);
201
+ }
202
+ else {
203
+ peers.push(`${pkg}@${version}`);
204
+ }
205
+ }
206
+ if (options.peerDependencies && peers.length) {
207
+ console.info('正在安装 peerDependencies...');
208
+ installNpmPkg(peers, options);
209
+ }
210
+ return output;
211
+ }
212
+ const callPlugin = async (pluginName, content, file, config, root) => {
213
+ const pluginFn = await getNpmPkg(`${exports.taroPluginPrefix}${pluginName}`, root);
214
+ return pluginFn(content, file, config);
215
+ };
216
+ exports.callPlugin = callPlugin;
217
+ const callPluginSync = (pluginName, content, file, config, root) => {
218
+ const pluginFn = getNpmPkgSync(`${exports.taroPluginPrefix}${pluginName}`, root);
219
+ return pluginFn(content, file, config);
220
+ };
221
+ exports.callPluginSync = callPluginSync;
222
+ function getNpmPkgSync(npmName, root) {
223
+ const npmPath = resolveNpmSync(npmName, root);
224
+ const npmFn = require(npmPath);
225
+ return npmFn;
226
+ }
227
+ async function getNpmPkg(npmName, root) {
228
+ let npmPath;
229
+ try {
230
+ npmPath = resolveNpmSync(npmName, root);
231
+ }
232
+ catch (err) {
233
+ if (err.code === 'MODULE_NOT_FOUND') {
234
+ console.error('!!! CAUGHT FATAL !!!', err, err.stack);
235
+ const installOptions = {
236
+ dev: false,
237
+ };
238
+ if (npmName.indexOf(exports.taroPluginPrefix) >= 0) {
239
+ installOptions.dev = true;
240
+ }
241
+ installNpmPkg(npmName, installOptions);
242
+ npmPath = await resolveNpm(npmName, root);
243
+ }
244
+ }
245
+ const npmFn = require(npmPath);
246
+ return npmFn;
247
+ }
248
+ //# sourceMappingURL=npm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm.js","sourceRoot":"","sources":["../src/npm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,gCAoCC;AAED,wCA+CC;AAED,sCAmEC;AAwBD,sCAIC;AAED,8BAmBC;AAvOD,8CAAgC;AAIhC,MAAM,KAAK,GAAG,6CAA6C,CAAC;AAC5D,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,MAAM,SAAS,GAAa,EAAE,CAAC;AAc/B,MAA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,UAAU,SAAS,CAAC,OAAe,EAAE,IAAY;IAC3D,IAAI,OAAO,CAAC;IACZ,IAAI,CAAC;QACH,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAAyB,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,EAAG,GAAW,CAAC,KAAK,CAAC,CAAC;YAC/D,MAAM,cAAc,GAAoB;gBACtC,GAAG,EAAE,KAAK;aACX,CAAC;YACF,IAAI,OAAO,CAAC,OAAO,CAAC,wBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3C,cAAc,CAAC,GAAG,GAAG,IAAI,CAAC;YAC5B,CAAC;YACD,aAAa,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YACvC,OAAO,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,6 @@
1
+ interface ICreateSwcRegisterParam {
2
+ only: any;
3
+ plugins?: [string, any][];
4
+ }
5
+ export default function createSwcRegister({ only, plugins }: ICreateSwcRegisterParam): void;
6
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = createSwcRegister;
4
+ function createSwcRegister({ only, plugins }) {
5
+ const config = {
6
+ only: Array.from(new Set([...only])),
7
+ jsc: {
8
+ parser: {
9
+ syntax: 'typescript',
10
+ decorators: true,
11
+ },
12
+ transform: {
13
+ legacyDecorator: true,
14
+ },
15
+ },
16
+ module: {
17
+ type: 'commonjs',
18
+ },
19
+ };
20
+ if (plugins) {
21
+ config.jsc.experimental = {
22
+ plugins,
23
+ };
24
+ }
25
+ require('@swc/register')(config);
26
+ }
27
+ //# sourceMappingURL=swcRegister.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swcRegister.js","sourceRoot":"","sources":["../src/swcRegister.ts"],"names":[],"mappings":";;AAKA,oCAwBC;AAxBD,SAAwB,iBAAiB,CAAC,EAAE,IAAI,EAAE,OAAO,EAA2B;IAClF,MAAM,MAAM,GAAwB;QAClC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACpC,GAAG,EAAE;YACH,MAAM,EAAE;gBACN,MAAM,EAAE,YAAY;gBACpB,UAAU,EAAE,IAAI;aACjB;YACD,SAAS,EAAE;gBACT,eAAe,EAAE,IAAI;aACtB;SACF;QACD,MAAM,EAAE;YACN,IAAI,EAAE,UAAU;SACjB;KACF,CAAC;IAEF,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,GAAG,CAAC,YAAY,GAAG;YACxB,OAAO;SACR,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import chalk from 'chalk';
2
+ interface ITerminalLinkOptions {
3
+ target?: 'stdout' | 'stderr';
4
+ fallback?: boolean | ((text: string, url: string) => string);
5
+ [key: string]: unknown;
6
+ }
7
+ declare function terminalLink(text: string, url: string, { target, fallback }?: ITerminalLinkOptions): string;
8
+ declare namespace terminalLink {
9
+ var isSupported: boolean;
10
+ var stderr: typeof terminalLink;
11
+ }
12
+ export { chalk, terminalLink };