@ray-js/builder-mp 0.6.30 → 0.6.32

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/build.js CHANGED
@@ -8,52 +8,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
13
  };
25
14
  Object.defineProperty(exports, "__esModule", { value: true });
26
15
  const colors_1 = __importDefault(require("colors"));
27
- const path_1 = __importDefault(require("path"));
28
16
  const shared_1 = require("@ray-js/shared");
29
- const build_store_1 = __importDefault(require("@ray-core/build-store"));
30
- const API_1 = __importDefault(require("@ray-core/cli/lib/API"));
31
17
  const legacyExport_1 = require("@ray-core/cli/lib/legacyExport");
32
18
  const package_json_1 = __importDefault(require("@ray-core/cli/package.json"));
33
19
  const builder_1 = require("./builder");
34
- const app_entry_1 = __importDefault(require("./webpack/plugins/app-entry"));
35
20
  const build_rjs_1 = __importDefault(require("./build.rjs"));
21
+ const ray_core_1 = require("./ray-core");
36
22
  colors_1.default.enable();
37
23
  const LOG_PREFIX = 'builder-mp';
24
+ const defaultCompileOptions = {
25
+ cwd: process.cwd(),
26
+ source: 'src',
27
+ mode: 'development',
28
+ watch: false,
29
+ target: 'wechat',
30
+ mini: false,
31
+ analyze: false,
32
+ devtools: false,
33
+ debug: false,
34
+ output: 'dist',
35
+ };
38
36
  function build(options, context) {
39
37
  return __awaiter(this, void 0, void 0, function* () {
40
38
  const { api } = context;
41
- const compileOptions = Object.assign({
42
- cwd: process.cwd(),
43
- source: 'src',
44
- mode: 'development',
45
- watch: false,
46
- target: 'wechat',
47
- mini: false,
48
- analyze: false,
49
- devtools: false,
50
- debug: false,
51
- output: 'dist',
52
- }, options);
53
- shared_1.log.verbose(LOG_PREFIX, `compileOptions:`, compileOptions);
54
- const { cwd, source, watch, target, mini, analyze, output, devtools } = compileOptions;
55
- // 上下文共享 options
56
- builder_1.builder.options = compileOptions;
39
+ let compileOptions = Object.assign({}, defaultCompileOptions, options);
40
+ const { cwd, target, output, devtools } = compileOptions;
57
41
  /**
58
42
  * 又是历史原因
59
43
  * 因老项目生成的产物目录是tuya,所以就干脆是tuya,不然会出现既 tuya 又 thing 的目录
@@ -61,174 +45,20 @@ function build(options, context) {
61
45
  */
62
46
  const dist = target === 'thing' ? 'tuya' : target;
63
47
  const outputPath = (0, shared_1.resolvePath)([output, dist], { cwd });
48
+ // 上下文共享 options
49
+ builder_1.builder.api = api;
50
+ builder_1.builder.options = compileOptions = Object.assign({}, compileOptions, { output: outputPath });
51
+ shared_1.log.verbose(LOG_PREFIX, `compileOptions:`, compileOptions);
64
52
  shared_1.log.info(LOG_PREFIX, '@ray-core/cli:'.green, `v${package_json_1.default.version}`);
65
53
  shared_1.log.info(LOG_PREFIX, 'cwd:'.green, cwd.underline);
66
54
  shared_1.log.info(LOG_PREFIX, 'outputDir:'.green, outputPath.underline);
67
- devtools &&
68
- shared_1.log.info(LOG_PREFIX, '开启 devtools 开发者工具环境变量'.yellow, 'process.evn.TUYA_DEVTOOLS');
69
- const _a = (0, legacyExport_1.getDefaultOptions)(), { UNSAFE_wechatTemplateDepth } = _a, remaxDefaultOptions = __rest(_a, ["UNSAFE_wechatTemplateDepth"]);
70
- const remaxBuildConfig = Object.assign(Object.assign({}, remaxDefaultOptions), { UNSAFE_wechatTemplateDepth: Object.assign(UNSAFE_wechatTemplateDepth, {
71
- swiper: 3,
72
- text: 1,
73
- ad: -1,
74
- 'match-media': -1,
75
- 'page-container': -1,
76
- 'share-element': -1,
77
- 'keyboard-accessory': -1,
78
- 'voip-room': -1,
79
- 'ad-custom': -1,
80
- 'page-meta': -1,
81
- 'navigation-bar': -1,
82
- }), compressTemplate: mini, pxToRpx: false, minimize: mini, analyze,
83
- cwd, loglevel: 'warn', rootDir: source, target, output: path_1.default.relative(cwd, outputPath), watch,
84
- configWebpack(context) {
85
- const { config, addCSSRule } = context;
86
- addCSSRule({
87
- name: 'less',
88
- test: /\.less(\?.*)?$/,
89
- loader: require.resolve('less-loader'),
90
- options: {},
91
- });
92
- (0, app_entry_1.default)(config);
93
- // 删除 clean-webpack-plugin 插件
94
- config.plugins.delete('clean-webpack-plugin');
95
- // 修改 mini-css-extract-plugin 的配置
96
- config
97
- .plugin('mini-css-extract-plugin')
98
- .tap(([options]) => [Object.assign(Object.assign({}, options), { ignoreOrder: true })]);
99
- config.devtool(builder_1.builder.options.watch ? 'cheap-module-source-map' : false);
100
- // const moduleMatcher = config.module.rule('js').values()[0]
101
- // 收敛 babel.config 配置
102
- // 调整 ray-core 的 babel 配置
103
- const babelConfigFile = path_1.default.resolve(__dirname, './babel/configs/babel.config.js');
104
- config.module
105
- .rule('js')
106
- .exclude.add((m) => /\.rjs$/i.test(m))
107
- .end()
108
- // 此次使用的 loader 是走了 ray-core 自定义的 babel
109
- // @see https://registry.code.tuya-inc.top/godzilla/ray-core/blob/87d114dc33690c09202054a2fa3fc9b770455935/packages/remax-cli/src/build/webpack/config.mini.ts#L122
110
- .use('babel')
111
- .tap((options) => {
112
- return Object.assign(Object.assign({}, options), { configFile: babelConfigFile, usePlugins: [
113
- require.resolve('./babel/plugins/ray-page-context/index'),
114
- ...options.usePlugins,
115
- ] });
116
- })
117
- .end()
118
- .end();
119
- // hooks
120
- // .rule('ray-hooks')
121
- // .test(moduleMatcher)
122
- // .exclude.add(
123
- // (m: string) =>
124
- // /\.rjs/i.test(m) || /node_modules\/(react|react-reconciler|react-dom)/.test(m)
125
- // )
126
- // .end()
127
- // .pre()
128
- // .use('hooks-loader')
129
- // .loader(require.resolve('babel-loader'))
130
- // .options({
131
- // babelrc: false,
132
- // presets: ['@babel/preset-typescript'],
133
- // plugins: [
134
- // // 替换 usePageEvent useAppEvent hooks api 模块名
135
- // [require.resolve('./babel/plugins/ray-hooks/index')],
136
- // '@babel/plugin-syntax-jsx',
137
- // [
138
- // '@babel/plugin-proposal-decorators',
139
- // {
140
- // legacy: true,
141
- // },
142
- // ],
143
- // ],
144
- // })
145
- // .end()
146
- // .end()
147
- // env-loader 将 isTuya 根据platform 转成 var isTuya = true 或 false
148
- // .rule('env-loader')
149
- // .test(moduleMatcher)
150
- // .exclude.add((m: string) => {
151
- // return /node_modules\/(?!(?:@ray-js|@ray-core)\/)/.test(m) || /\.rjs$/i.test(m)
152
- // })
153
- // .end()
154
- // .pre()
155
- // .use('env-loader')
156
- // .loader(require.resolve('@ray-js/env-loader'))
157
- // .options({ platform: target })
158
- // .end()
159
- // .end()
160
- // context
161
- // .rule('ray-context')
162
- // .test(moduleMatcher)
163
- // .include.add(path.join(builder.options.cwd!, builder.options.source!))
164
- // .end()
165
- // .exclude.add((m: string) => /\.rjs/i.test(m))
166
- // .end()
167
- // .pre()
168
- // .use('context-loader')
169
- // .loader(require.resolve('babel-loader'))
170
- // .options({
171
- // babelrc: false,
172
- // presets: ['@babel/preset-typescript'],
173
- // plugins: [
174
- // require.resolve('./babel/plugins/a'),
175
- // // 对项目下的文件进行 context 实例的包裹 透传如 pageConfig appConfig
176
- // [require.resolve('./babel/plugins/ray-page-context/index')],
177
- // '@babel/plugin-syntax-jsx',
178
- // [
179
- // '@babel/plugin-proposal-decorators',
180
- // {
181
- // legacy: true,
182
- // },
183
- // ],
184
- // require.resolve('./babel/plugins/b'),
185
- // ],
186
- // })
187
- // .end()
188
- // .end()
189
- config.module
190
- .rule('rjs')
191
- .test(/\.rjs$/)
192
- .use('rjs-loader')
193
- .loader(require.resolve('./webpack/loaders/rjs/index'))
194
- .end();
195
- config.plugin('webpack-define-plugin').tap(([args]) => {
196
- return [Object.assign(Object.assign({}, args), { 'process.env.PLATFORM': JSON.stringify(target) })];
197
- });
198
- config.resolve.alias.set('@ray-core/ray', path_1.default.dirname(require.resolve('@ray-core/ray/package.json')));
199
- config.resolve.alias.set('@ray-core/runtime', path_1.default.dirname(require.resolve('@ray-core/runtime/package.json')));
200
- config.resolve.alias.set('react', path_1.default.dirname(require.resolve('react/package.json')));
201
- config.resolve.alias.set('@ray-js/router', '@ray-js/router-mp');
202
- config.resolve.alias.set('@ray-js/framework', '@ray-js/framework-mp');
203
- // @ray-core/plugin-error-screen 使用到的 @ray-core one
204
- config.resolve.alias.set('@ray-core/one', path_1.default.dirname(require.resolve('@ray-js/components/package.json')));
205
- api.configIntoWebpackConfig(config);
206
- api.callPluginMethod('configWebpack', { config });
207
- builder_1.builder.entry = config.toConfig().entry;
208
- build_rjs_1.default.config(config);
209
- } });
210
- const remaxApi = new API_1.default();
211
- const originalRemax = remaxApi.registerAdapterPlugins;
212
- // FIXME: ray 支持注册其他平台适配器
213
- remaxApi.registerAdapterPlugins = function (target) {
214
- if (target === 'thing') {
215
- this.adapter.target = target;
216
- this.adapter.packageName = '@ray-js/adapter';
217
- const packagePath = this.adapter.packageName + '/node';
218
- // eslint-disable-next-line @typescript-eslint/no-var-requires
219
- let plugin = require(packagePath).default || require(packagePath);
220
- plugin = typeof plugin === 'function' ? plugin() : plugin;
221
- build_store_1.default.skipHostComponents = plugin.skipHostComponents;
222
- // @ts-ignore
223
- this.registerHostComponents(plugin.hostComponents);
224
- this.plugins.push(plugin);
225
- }
226
- else {
227
- originalRemax.call(this, target);
228
- }
229
- };
55
+ if (devtools) {
56
+ shared_1.log.info(LOG_PREFIX, '开启 devtools 开发者工具环境变量'.yellow, devtools);
57
+ }
58
+ const rayCoreOpts = (0, ray_core_1.getRayCoreOptions)(build_rjs_1.default);
59
+ const rayApi = new ray_core_1.RayAPI(rayCoreOpts);
230
60
  // 编译除rjs模块外的小程序模块
231
- const compiler = (0, legacyExport_1.buildMini)(remaxApi, Object.assign({}, remaxBuildConfig));
61
+ const compiler = (0, legacyExport_1.buildMini)(rayApi, rayCoreOpts);
232
62
  build_rjs_1.default.init(compiler, compileOptions); // TODO rjs 可用动态虚拟模块实现单webpack编译
233
63
  return compiler;
234
64
  });
@@ -1,6 +1,6 @@
1
1
  import Config from 'webpack-chain';
2
2
  import { Compiler, Stats } from 'webpack';
3
- declare class Builder {
3
+ export declare class RjsBuilder {
4
4
  private compiler;
5
5
  private parentCompiler;
6
6
  private entries;
@@ -16,5 +16,5 @@ declare class Builder {
16
16
  createWebpackHook(): void;
17
17
  extractRjsModuleHook(): void;
18
18
  }
19
- declare const rjsBuilder: Builder;
19
+ declare const rjsBuilder: RjsBuilder;
20
20
  export default rjsBuilder;
package/lib/build.rjs.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RjsBuilder = void 0;
6
7
  const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
7
8
  const webpack_1 = require("webpack");
8
9
  const path_1 = __importDefault(require("path"));
@@ -40,7 +41,7 @@ const replaceModeContent = (content) => content.replace(/__minipack_require__/g,
40
41
  const isSupportMultiRjs = false;
41
42
  const LOG_PREFIX = 'builder-mp';
42
43
  const LOG_PREFIX_RJS = 'builder-rjs';
43
- class Builder {
44
+ class RjsBuilder {
44
45
  constructor() {
45
46
  this.init = (parentCompiler, compileOptions) => {
46
47
  this.parentCompiler = parentCompiler;
@@ -209,5 +210,6 @@ class Builder {
209
210
  });
210
211
  }
211
212
  }
212
- const rjsBuilder = new Builder();
213
+ exports.RjsBuilder = RjsBuilder;
214
+ const rjsBuilder = new RjsBuilder();
213
215
  exports.default = rjsBuilder;
package/lib/builder.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import { Entry } from 'webpack';
2
- import { CliOptions } from '@ray-js/types';
2
+ import { CliOptions, API } from '@ray-js/types';
3
3
  export default class Builder {
4
4
  private cliOptions;
5
5
  private entryValue;
6
+ private _api;
6
7
  get options(): CliOptions;
7
8
  set options(v: CliOptions);
8
9
  get entry(): Entry;
9
10
  set entry(v: Entry);
11
+ get api(): API;
12
+ set api(api: API);
10
13
  }
11
14
  export declare const builder: Builder;
package/lib/builder.js CHANGED
@@ -17,6 +17,12 @@ class Builder {
17
17
  set entry(v) {
18
18
  this.entryValue = v;
19
19
  }
20
+ get api() {
21
+ return this._api;
22
+ }
23
+ set api(api) {
24
+ this._api = api;
25
+ }
20
26
  }
21
27
  exports.default = Builder;
22
28
  exports.builder = new Builder();
File without changes
File without changes
@@ -3,5 +3,11 @@ import Config from 'webpack-chain';
3
3
  * 小程序框架启动, 在文件顶部增加 .ray/main.mini 的适配
4
4
  * 读取 TabBar 信息,注册页面到 router 上。实现 web 路由的跳转
5
5
  */
6
- declare const _default: (config: Config) => void;
6
+ declare function configWebpack(context: {
7
+ config: Config;
8
+ }): void;
9
+ declare const _default: {
10
+ name: string;
11
+ configWebpack: typeof configWebpack;
12
+ };
7
13
  export default _default;
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  * 小程序框架启动, 在文件顶部增加 .ray/main.mini 的适配
8
8
  * 读取 TabBar 信息,注册页面到 router 上。实现 web 路由的跳转
9
9
  */
10
- exports.default = (config) => {
11
- const plugin = config.plugin('webpack-virtual-modulesapp');
10
+ function configWebpack(context) {
11
+ const plugin = context.config.plugin('webpack-virtual-modulesapp');
12
12
  const thePlugin = plugin.get('plugin');
13
13
  if (thePlugin._staticModules) {
14
14
  const file = Object.keys(thePlugin._staticModules).find((name) => /\/?app\./.test(name));
@@ -17,4 +17,8 @@ exports.default = (config) => {
17
17
  thePlugin._staticModules[file] = content;
18
18
  plugin.set('plugin', thePlugin);
19
19
  }
20
+ }
21
+ exports.default = {
22
+ name: 'app-entry-wrapper',
23
+ configWebpack,
20
24
  };
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ name: string;
3
+ configWebpack({ addCSSRule }: any): void;
4
+ };
5
+ export default _default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ name: 'add-less-support',
5
+ configWebpack({ addCSSRule }) {
6
+ addCSSRule({
7
+ name: 'less',
8
+ test: /\.less(\?.*)?$/,
9
+ loader: require.resolve('less-loader'),
10
+ options: {},
11
+ });
12
+ },
13
+ };
@@ -0,0 +1,8 @@
1
+ import Config from 'webpack-chain';
2
+ declare const _default: {
3
+ name: string;
4
+ configWebpack(context: {
5
+ config: Config;
6
+ }): void;
7
+ };
8
+ export default _default;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const shared_1 = require("@ray-js/shared");
8
+ const slash_1 = __importDefault(require("slash"));
9
+ const builder_1 = require("../builder");
10
+ function alias(alias, mod, config) {
11
+ const api = builder_1.builder.api;
12
+ const cwd = api.options.cwd;
13
+ let rayMod;
14
+ try {
15
+ rayMod = require.resolve(`${cwd}/node_modules/${mod}`);
16
+ }
17
+ catch (e) {
18
+ rayMod = require.resolve(mod);
19
+ shared_1.log.warn('', `Can't resolve module '${mod}' in ${cwd}`.yellow);
20
+ }
21
+ rayMod = (0, slash_1.default)(path_1.default.dirname(rayMod));
22
+ config.resolve.alias.set(alias, rayMod);
23
+ }
24
+ exports.default = {
25
+ name: 'mini-app-module-resolve',
26
+ configWebpack(context) {
27
+ const { config } = context;
28
+ const { target } = builder_1.builder.options;
29
+ alias('ray', '@ray-js/ray', config);
30
+ // 修改 mini-css-extract-plugin 的配置
31
+ config.plugin('mini-css-extract-plugin').tap(([options]) => [Object.assign(Object.assign({}, options), { ignoreOrder: true })]);
32
+ // 收敛 babel.config 配置
33
+ // 调整 ray-core 的 babel 配置
34
+ config.module
35
+ .rule('js')
36
+ .exclude.add((m) => /\.rjs$/i.test(m))
37
+ .end()
38
+ .use('babel')
39
+ .tap((options) => {
40
+ // 修复 babel alias 错误问题
41
+ const plugins = options.usePlugins.map((p) => {
42
+ if (Object.prototype.toString.call(p) === '[object Array]') {
43
+ const [m, opts] = p;
44
+ const r = config.resolve.alias.get('ray');
45
+ if (m.indexOf('babel-plugin-module-resolver') !== -1 && r) {
46
+ opts.alias = Object.assign(Object.assign({}, opts.alias), { ray: r });
47
+ return [m, opts];
48
+ }
49
+ return p;
50
+ }
51
+ return p;
52
+ });
53
+ return Object.assign(Object.assign({}, options), { configFile: path_1.default.resolve(__dirname, '../babel/configs/babel.config.js'), usePlugins: [require.resolve('../babel/plugins/ray-page-context/index'), ...plugins] });
54
+ })
55
+ .end()
56
+ .end();
57
+ config.module
58
+ .rule('rjs')
59
+ .test(/\.rjs$/)
60
+ .use('rjs-loader')
61
+ .loader(require.resolve('../loaders/rjs/index'))
62
+ .end();
63
+ config.plugin('webpack-define-plugin').tap(([args]) => {
64
+ return [Object.assign(Object.assign({}, args), { 'process.env.PLATFORM': JSON.stringify(target) })];
65
+ });
66
+ config.resolve.alias.set('@ray-core/ray', path_1.default.dirname(require.resolve('@ray-core/ray/package.json')));
67
+ config.resolve.alias.set('@ray-core/runtime', path_1.default.dirname(require.resolve('@ray-core/runtime/package.json')));
68
+ // @ray-core/plugin-error-screen 使用到的 @ray-core one
69
+ config.resolve.alias.set('@ray-core/one', path_1.default.dirname(require.resolve('@ray-js/components/package.json')));
70
+ config.resolve.alias.set('react', path_1.default.dirname(require.resolve('react/package.json')));
71
+ config.resolve.alias.set('@ray-js/router', '@ray-js/router-mp');
72
+ config.resolve.alias.set('@ray-js/framework', '@ray-js/framework-mp');
73
+ builder_1.builder.entry = config.toConfig().entry;
74
+ },
75
+ };
@@ -0,0 +1,8 @@
1
+ import Config from 'webpack-chain';
2
+ declare const _default: {
3
+ name: string;
4
+ configWebpack(context: {
5
+ config: Config;
6
+ }): void;
7
+ };
8
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const builder_1 = require("../builder");
4
+ exports.default = {
5
+ name: 'old-project-module-resolve-legacy',
6
+ configWebpack(context) {
7
+ const config = context.config;
8
+ const resolveConfig = builder_1.builder.api.config.resolveAlias;
9
+ // 兼容老项目中的老配置
10
+ if (resolveConfig) {
11
+ process.emitWarning(`config.resolveAlias has deprecated!, please use {
12
+ plugins: [
13
+ {
14
+ configWebpack({ config }) {
15
+ config.resolve.alias.set(key, value)
16
+ }
17
+ }
18
+ ]
19
+ } plugin instead.`);
20
+ Object.entries(resolveConfig).forEach(([key, value]) => {
21
+ config.resolve.alias.set(key, value);
22
+ });
23
+ }
24
+ },
25
+ };
@@ -0,0 +1,8 @@
1
+ import type { Options, Platform } from '@ray-core/types';
2
+ import RayCoreAPI from '@ray-core/cli/lib/API';
3
+ import type { RjsBuilder } from './build.rjs';
4
+ export declare function getRayCoreOptions(rjsBuilder: RjsBuilder): Options;
5
+ export declare class RayAPI extends RayCoreAPI {
6
+ constructor(opts: Options);
7
+ registerAdapterPlugins(target: Platform): void;
8
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RayAPI = exports.getRayCoreOptions = void 0;
18
+ const path_1 = __importDefault(require("path"));
19
+ const legacyExport_1 = require("@ray-core/cli/lib/legacyExport");
20
+ const API_1 = __importDefault(require("@ray-core/cli/lib/API"));
21
+ const build_store_1 = __importDefault(require("@ray-core/build-store"));
22
+ const resolve_alias_1 = __importDefault(require("./plugins/resolve-alias"));
23
+ const app_entry_1 = __importDefault(require("./plugins/app-entry"));
24
+ const less_1 = __importDefault(require("./plugins/less"));
25
+ const resolve_legacy_1 = __importDefault(require("./plugins/resolve-legacy"));
26
+ const builder_1 = require("./builder");
27
+ const _a = (0, legacyExport_1.getDefaultOptions)(), { UNSAFE_wechatTemplateDepth } = _a, remaxDefaultOptions = __rest(_a, ["UNSAFE_wechatTemplateDepth"]);
28
+ const defaultTemplateDepth = {
29
+ swiper: 3,
30
+ text: 1,
31
+ ad: -1,
32
+ 'match-media': -1,
33
+ 'page-container': -1,
34
+ 'share-element': -1,
35
+ 'keyboard-accessory': -1,
36
+ 'voip-room': -1,
37
+ 'ad-custom': -1,
38
+ 'page-meta': -1,
39
+ 'navigation-bar': -1,
40
+ };
41
+ const innerPlugins = [resolve_legacy_1.default, app_entry_1.default, less_1.default, resolve_alias_1.default];
42
+ function getRayCoreOptions(rjsBuilder) {
43
+ const { cwd, source, watch, target, mini, analyze, output } = builder_1.builder.options;
44
+ const api = builder_1.builder.api;
45
+ const injectWebpackConfigToRjs = {
46
+ configWebpack({ config }) {
47
+ rjsBuilder.config(config);
48
+ },
49
+ };
50
+ // @ts-ignore
51
+ const plugins = innerPlugins.concat(api.plugins, injectWebpackConfigToRjs);
52
+ const remaxBuildConfig = Object.assign(Object.assign({}, remaxDefaultOptions), { UNSAFE_wechatTemplateDepth: Object.assign(UNSAFE_wechatTemplateDepth, defaultTemplateDepth), compressTemplate: mini, pxToRpx: false, minimize: mini, analyze,
53
+ cwd, loglevel: 'warn', rootDir: source, target, output: path_1.default.relative(cwd, output), watch,
54
+ plugins });
55
+ return remaxBuildConfig;
56
+ }
57
+ exports.getRayCoreOptions = getRayCoreOptions;
58
+ class RayAPI extends API_1.default {
59
+ constructor(opts) {
60
+ super();
61
+ this.registerPlugins(opts.plugins);
62
+ }
63
+ registerAdapterPlugins(target) {
64
+ if (target === 'thing') {
65
+ this.adapter.target = target;
66
+ this.adapter.packageName = '@ray-js/adapter';
67
+ const packagePath = this.adapter.packageName + '/node';
68
+ let plugin = require(packagePath).default || require(packagePath);
69
+ plugin = typeof plugin === 'function' ? plugin() : plugin;
70
+ build_store_1.default.skipHostComponents = plugin.skipHostComponents;
71
+ // @ts-ignore
72
+ this.registerHostComponents(plugin.hostComponents);
73
+ this.plugins.push(plugin);
74
+ }
75
+ else {
76
+ super.registerAdapterPlugins(target);
77
+ }
78
+ }
79
+ }
80
+ exports.RayAPI = RayAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/builder-mp",
3
- "version": "0.6.30",
3
+ "version": "0.6.32",
4
4
  "description": "Ray builder for mini program",
5
5
  "keywords": [
6
6
  "ray"
@@ -24,13 +24,13 @@
24
24
  "@babel/template": "^7.16.0",
25
25
  "@babel/traverse": "^7.16.3",
26
26
  "@babel/types": "^7.16.0",
27
- "@ray-core/babel-preset-remax": "^0.0.x",
28
- "@ray-core/build-store": "^0.0.x",
29
- "@ray-core/cli": "^0.0.x",
30
- "@ray-core/ray": "^0.0.x",
31
- "@ray-js/adapter": "^0.6.30",
32
- "@ray-js/shared": "^0.6.30",
33
- "@ray-js/types": "^0.6.30",
27
+ "@ray-core/babel-preset-remax": "^0.1.x",
28
+ "@ray-core/build-store": "^0.1.x",
29
+ "@ray-core/cli": "^0.1.x",
30
+ "@ray-core/ray": "^0.1.x",
31
+ "@ray-js/adapter": "^0.6.32",
32
+ "@ray-js/shared": "^0.6.32",
33
+ "@ray-js/types": "^0.6.32",
34
34
  "babel-loader": "^8.2.3",
35
35
  "babel-plugin-minify-dead-code-elimination": "^0.5.1",
36
36
  "babel-plugin-transform-prune-unused-imports": "^1.0.1",
@@ -47,7 +47,7 @@
47
47
  "webpack-virtual-modules": "^0.4.4"
48
48
  },
49
49
  "devDependencies": {
50
- "@ray-core/types": "^0.0.x",
50
+ "@ray-core/types": "^0.1.x",
51
51
  "@types/jest": "^27.0.2",
52
52
  "@types/node": "^16.9.1",
53
53
  "babel-plugin-tester": "^10.1.0",
@@ -61,6 +61,6 @@
61
61
  "email": "tuyafe@tuya.com"
62
62
  }
63
63
  ],
64
- "gitHead": "03e187194ad2bf41d20b7796d67e12bf77ba9c7f",
64
+ "gitHead": "cca49d95837e248eb6471a3802a7f1461d482f71",
65
65
  "repository": {}
66
66
  }
@@ -1,5 +0,0 @@
1
- declare type Deps = {
2
- [key: string]: string;
3
- };
4
- export default function analyzeRjsModuleName(entry: string): Deps;
5
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const parser_1 = require("@babel/parser");
7
- const traverse_1 = __importDefault(require("@babel/traverse"));
8
- const fs_1 = require("fs");
9
- const path_1 = require("path");
10
- const hash_replace_1 = __importDefault(require("hash-replace"));
11
- const hash = (0, hash_replace_1.default)('hash');
12
- function analyzeRjsModuleName(entry) {
13
- const deps = {};
14
- function handle(filename) {
15
- filename = (0, path_1.normalize)(filename);
16
- if (Object.keys(deps).includes(filename)) {
17
- console.warn(`duplicated dependency: ${filename}`);
18
- return;
19
- }
20
- const source = (0, fs_1.readFileSync)(filename).toString();
21
- const ast = (0, parser_1.parse)(source, { sourceType: 'module', plugins: ['jsx', 'typescript'] });
22
- const x = (0, traverse_1.default)(ast, {
23
- enter: (path) => {
24
- if (path.node.type === 'ImportDeclaration') {
25
- const context = (0, path_1.dirname)(filename);
26
- filename = (0, path_1.resolve)(context, path.node.source.value);
27
- const moduleName = hash('[hash:7].rjs', null, source);
28
- deps[filename] = moduleName;
29
- handle(filename);
30
- }
31
- if (path.node.type === 'VariableDeclaration') {
32
- }
33
- },
34
- });
35
- }
36
- handle(entry);
37
- return deps;
38
- }
39
- exports.default = analyzeRjsModuleName;
@@ -1,2 +0,0 @@
1
- declare const _default: {};
2
- export default _default;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {};