@modern-js/app-tools 0.0.0-nightly-20240304170717 → 0.0.0-nightly-20240306170726

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.
@@ -49,11 +49,12 @@ async function generateBuilder(options, bundlerType) {
49
49
  return builder;
50
50
  }
51
51
  async function applyBuilderPlugins(builder, options) {
52
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
52
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
53
53
  builder.addPlugins([
54
54
  builderPluginAdapterBasic(),
55
55
  builderPluginAdapterSSR(options),
56
- builderPluginAdapterHtml(options)
56
+ builderPluginAdapterHtml(options),
57
+ builderPluginAdapterWorker()
57
58
  ]);
58
59
  const { normalizedConfig } = options;
59
60
  if (!normalizedConfig.output.disableNodePolyfill) {
@@ -33,6 +33,7 @@ __export(adapterSSR_exports, {
33
33
  module.exports = __toCommonJS(adapterSSR_exports);
34
34
  var path = __toESM(require("path"));
35
35
  var import_shared = require("@rsbuild/shared");
36
+ var import_core = require("@rsbuild/core");
36
37
  var import_utils = require("@modern-js/utils");
37
38
  var import_bundlerPlugins = require("../bundlerPlugins");
38
39
  var import_utils2 = require("../../../analyze/utils");
@@ -42,7 +43,7 @@ const builderPluginAdapterSSR = (options) => ({
42
43
  const { normalizedConfig } = options;
43
44
  api.modifyRsbuildConfig((config) => {
44
45
  if (isStreamingSSR(normalizedConfig)) {
45
- return (0, import_shared.mergeRsbuildConfig)(config, {
46
+ return (0, import_core.mergeRsbuildConfig)(config, {
46
47
  html: {
47
48
  inject: "body"
48
49
  }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var adapterWorker_exports = {};
20
+ __export(adapterWorker_exports, {
21
+ builderPluginAdapterWorker: () => builderPluginAdapterWorker
22
+ });
23
+ module.exports = __toCommonJS(adapterWorker_exports);
24
+ var import_path = require("path");
25
+ const getDistPath = (outputConfig, type) => {
26
+ const { distPath } = outputConfig;
27
+ const ret = distPath[type];
28
+ if (typeof ret !== "string") {
29
+ throw new Error(`unknown key ${type} in "output.distPath"`);
30
+ }
31
+ return ret;
32
+ };
33
+ const builderPluginAdapterWorker = () => ({
34
+ name: "builder-plugin-adapter-worker",
35
+ setup(api) {
36
+ api.modifyBundlerChain(async (chain, { isServiceWorker }) => {
37
+ const config = api.getNormalizedConfig();
38
+ if (isServiceWorker) {
39
+ const workerPath = getDistPath(config.output, "worker");
40
+ const filename = import_path.posix.join(workerPath, `[name].js`);
41
+ chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
42
+ }
43
+ });
44
+ }
45
+ });
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ builderPluginAdapterWorker
49
+ });
@@ -18,9 +18,11 @@ module.exports = __toCommonJS(builderPlugins_exports);
18
18
  __reExport(builderPlugins_exports, require("./adapterBasic"), module.exports);
19
19
  __reExport(builderPlugins_exports, require("./adapterHtml"), module.exports);
20
20
  __reExport(builderPlugins_exports, require("./adapterSSR"), module.exports);
21
+ __reExport(builderPlugins_exports, require("./adapterWorker"), module.exports);
21
22
  // Annotate the CommonJS export names for ESM import in node:
22
23
  0 && (module.exports = {
23
24
  ...require("./adapterBasic"),
24
25
  ...require("./adapterHtml"),
25
- ...require("./adapterSSR")
26
+ ...require("./adapterSSR"),
27
+ ...require("./adapterWorker")
26
28
  });
@@ -48,7 +48,7 @@ function applyBuilderPlugins(builder, options) {
48
48
  }
49
49
  function _applyBuilderPlugins() {
50
50
  _applyBuilderPlugins = _async_to_generator(function(builder, options) {
51
- var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, normalizedConfig, pluginNodePolyfill;
51
+ var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker, normalizedConfig, pluginNodePolyfill;
52
52
  return _ts_generator(this, function(_state) {
53
53
  switch (_state.label) {
54
54
  case 0:
@@ -57,11 +57,12 @@ function _applyBuilderPlugins() {
57
57
  import("../shared/builderPlugins")
58
58
  ];
59
59
  case 1:
60
- _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR;
60
+ _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR, builderPluginAdapterWorker = _ref.builderPluginAdapterWorker;
61
61
  builder.addPlugins([
62
62
  builderPluginAdapterBasic(),
63
63
  builderPluginAdapterSSR(options),
64
- builderPluginAdapterHtml(options)
64
+ builderPluginAdapterHtml(options),
65
+ builderPluginAdapterWorker()
65
66
  ]);
66
67
  normalizedConfig = options.normalizedConfig;
67
68
  if (!!normalizedConfig.output.disableNodePolyfill)
@@ -1,7 +1,8 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import * as path from "path";
4
- import { isHtmlDisabled, mergeRsbuildConfig } from "@rsbuild/shared";
4
+ import { isHtmlDisabled } from "@rsbuild/shared";
5
+ import { mergeRsbuildConfig } from "@rsbuild/core";
5
6
  import { isSSR, fs } from "@modern-js/utils";
6
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
7
8
  import { getServerCombinedModueFile } from "../../../analyze/utils";
@@ -0,0 +1,41 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { posix } from "path";
4
+ var getDistPath = function(outputConfig, type) {
5
+ var distPath = outputConfig.distPath;
6
+ var ret = distPath[type];
7
+ if (typeof ret !== "string") {
8
+ throw new Error("unknown key ".concat(type, ' in "output.distPath"'));
9
+ }
10
+ return ret;
11
+ };
12
+ var builderPluginAdapterWorker = function() {
13
+ return {
14
+ name: "builder-plugin-adapter-worker",
15
+ setup: function setup(api) {
16
+ api.modifyBundlerChain(function() {
17
+ var _ref = _async_to_generator(function(chain, param) {
18
+ var isServiceWorker, config, workerPath, filename;
19
+ return _ts_generator(this, function(_state) {
20
+ isServiceWorker = param.isServiceWorker;
21
+ config = api.getNormalizedConfig();
22
+ if (isServiceWorker) {
23
+ workerPath = getDistPath(config.output, "worker");
24
+ filename = posix.join(workerPath, "[name].js");
25
+ chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
26
+ }
27
+ return [
28
+ 2
29
+ ];
30
+ });
31
+ });
32
+ return function(chain, _) {
33
+ return _ref.apply(this, arguments);
34
+ };
35
+ }());
36
+ }
37
+ };
38
+ };
39
+ export {
40
+ builderPluginAdapterWorker
41
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./adapterBasic";
2
2
  export * from "./adapterHtml";
3
3
  export * from "./adapterSSR";
4
+ export * from "./adapterWorker";
@@ -16,11 +16,12 @@ async function generateBuilder(options, bundlerType) {
16
16
  return builder;
17
17
  }
18
18
  async function applyBuilderPlugins(builder, options) {
19
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins");
19
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
20
20
  builder.addPlugins([
21
21
  builderPluginAdapterBasic(),
22
22
  builderPluginAdapterSSR(options),
23
- builderPluginAdapterHtml(options)
23
+ builderPluginAdapterHtml(options),
24
+ builderPluginAdapterWorker()
24
25
  ]);
25
26
  const { normalizedConfig } = options;
26
27
  if (!normalizedConfig.output.disableNodePolyfill) {
@@ -1,5 +1,6 @@
1
1
  import * as path from "path";
2
- import { isHtmlDisabled, mergeRsbuildConfig } from "@rsbuild/shared";
2
+ import { isHtmlDisabled } from "@rsbuild/shared";
3
+ import { mergeRsbuildConfig } from "@rsbuild/core";
3
4
  import { isSSR, fs } from "@modern-js/utils";
4
5
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
5
6
  import { getServerCombinedModueFile } from "../../../analyze/utils";
@@ -0,0 +1,25 @@
1
+ import { posix } from "path";
2
+ const getDistPath = (outputConfig, type) => {
3
+ const { distPath } = outputConfig;
4
+ const ret = distPath[type];
5
+ if (typeof ret !== "string") {
6
+ throw new Error(`unknown key ${type} in "output.distPath"`);
7
+ }
8
+ return ret;
9
+ };
10
+ const builderPluginAdapterWorker = () => ({
11
+ name: "builder-plugin-adapter-worker",
12
+ setup(api) {
13
+ api.modifyBundlerChain(async (chain, { isServiceWorker }) => {
14
+ const config = api.getNormalizedConfig();
15
+ if (isServiceWorker) {
16
+ const workerPath = getDistPath(config.output, "worker");
17
+ const filename = posix.join(workerPath, `[name].js`);
18
+ chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
19
+ }
20
+ });
21
+ }
22
+ });
23
+ export {
24
+ builderPluginAdapterWorker
25
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./adapterBasic";
2
2
  export * from "./adapterHtml";
3
3
  export * from "./adapterSSR";
4
+ export * from "./adapterWorker";
@@ -0,0 +1,2 @@
1
+ import { RsbuildPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginAdapterWorker: () => RsbuildPlugin;
@@ -1,3 +1,4 @@
1
1
  export * from './adapterBasic';
2
2
  export * from './adapterHtml';
3
3
  export * from './adapterSSR';
4
+ export * from './adapterWorker';
@@ -1,3 +1,3 @@
1
1
  import type { AppLegacyNormalizedConfig, AppLegacyUserConfig, AppNormalizedConfig, AppUserConfig } from '../../types';
2
2
  export declare function transformNormalizedConfig(config: AppLegacyNormalizedConfig): AppNormalizedConfig<'webpack'>;
3
- export declare function checkIsLegacyConfig(config: AppLegacyUserConfig | AppUserConfig): config is AppLegacyUserConfig;
3
+ export declare function checkIsLegacyConfig(config: AppLegacyUserConfig | AppUserConfig<'shared'>): config is AppLegacyUserConfig;
@@ -4,7 +4,7 @@ import type { AppLegacyUserConfig, AppUserConfig } from './types';
4
4
  * This function helps you to autocomplete configuration types.
5
5
  * It accepts a direct config object, or a function that returns a config.
6
6
  */
7
- export declare const defineConfig: <B extends "rspack" | "webpack" = "webpack">(config: UserConfigExport<AppUserConfig<B_1>>) => UserConfigExport<AppUserConfig<B_1>>;
7
+ export declare const defineConfig: <B extends "rspack" | "webpack" = "webpack">(config: UserConfigExport<AppUserConfig<B>>) => UserConfigExport<AppUserConfig<B>>;
8
8
  /**
9
9
  * @deprecated Please use `defineConfig` instead.
10
10
  * `defineLegacyConfig` will be removed in the future major version.
@@ -1,5 +1,6 @@
1
1
  import type { ServerUserConfig, BffUserConfig } from '@modern-js/server-core';
2
2
  import type { UniBuilderPlugin } from '@modern-js/uni-builder';
3
+ import type { Bundler } from '../utils';
3
4
  import type { OutputUserConfig } from './output';
4
5
  import type { SourceUserConfig } from './source';
5
6
  import type { TestingUserConfig } from './testing';
@@ -17,7 +18,7 @@ export interface RuntimeUserConfig {
17
18
  export interface RuntimeByEntriesUserConfig {
18
19
  [name: string]: RuntimeUserConfig;
19
20
  }
20
- export interface AppToolsUserConfig {
21
+ export interface AppToolsUserConfig<B extends Bundler> {
21
22
  server?: ServerUserConfig;
22
23
  source?: SourceUserConfig;
23
24
  output?: OutputUserConfig;
@@ -33,7 +34,7 @@ export interface AppToolsUserConfig {
33
34
  runtime?: RuntimeUserConfig;
34
35
  runtimeByEntries?: RuntimeByEntriesUserConfig;
35
36
  html?: HtmlUserConfig;
36
- tools?: ToolsUserConfig;
37
+ tools?: ToolsUserConfig<B>;
37
38
  security?: SecurityUserConfig;
38
39
  testing?: TestingUserConfig;
39
40
  builderPlugins?: UniBuilderPlugin[];
@@ -44,4 +45,4 @@ interface SharedNormalizedConfig<RawConfig> {
44
45
  cliOptions?: Record<string, any>;
45
46
  _raw: RawConfig;
46
47
  }
47
- export type AppToolsNormalizedConfig<Config = AppToolsUserConfig> = Required<Config> & SharedNormalizedConfig<Config>;
48
+ export type AppToolsNormalizedConfig<Config = AppToolsUserConfig<'shared'>> = Required<Config> & SharedNormalizedConfig<Config>;
@@ -2,9 +2,10 @@ import type { JestConfig } from '@modern-js/types';
2
2
  import type { PluginSwcOptions } from '@rsbuild/plugin-swc';
3
3
  import type { PluginEsbuildOptions } from '@rsbuild/plugin-esbuild';
4
4
  import type { UniBuilderConfig } from '@modern-js/uni-builder';
5
- import type { UnwrapBuilderConfig } from '../utils';
5
+ import type { UnwrapBuilderConfig, Bundler } from '../utils';
6
6
  export type Tailwindcss = Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
7
- export interface ToolsUserConfig extends UnwrapBuilderConfig<UniBuilderConfig, 'tools'> {
7
+ type BuilderToolsConfig = UnwrapBuilderConfig<UniBuilderConfig, 'tools'>;
8
+ export interface ToolsUserConfig<B extends Bundler = 'webpack'> extends Omit<BuilderToolsConfig, 'swc'> {
8
9
  /**
9
10
  * Used to custom Tailwind CSS configurations.
10
11
  * @requires `tailwindcss` plugin.
@@ -25,7 +26,7 @@ export interface ToolsUserConfig extends UnwrapBuilderConfig<UniBuilderConfig, '
25
26
  * The configuration of `swc` is provided by `swc` plugin.
26
27
  * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
27
28
  */
28
- swc?: PluginSwcOptions<'outer'>;
29
+ swc?: B extends 'shared' ? undefined : B extends 'webpack' ? PluginSwcOptions<'outer'> : BuilderToolsConfig['swc'];
29
30
  /**
30
31
  * Used to custom Esbuild configurations.
31
32
  * @requires `esbuild` plugin.
@@ -34,3 +35,4 @@ export interface ToolsUserConfig extends UnwrapBuilderConfig<UniBuilderConfig, '
34
35
  */
35
36
  esbuild?: PluginEsbuildOptions;
36
37
  }
38
+ export {};
@@ -12,8 +12,8 @@ export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormal
12
12
  export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig, } from '@modern-js/core';
13
13
  export type AppTools<B extends Bundler = 'webpack'> = {
14
14
  hooks: AppToolsHooks<B>;
15
- userConfig: AppToolsUserConfig;
16
- normalizedConfig: AppToolsNormalizedConfig<AppToolsUserConfig>;
15
+ userConfig: AppToolsUserConfig<B>;
16
+ normalizedConfig: AppToolsNormalizedConfig<AppToolsUserConfig<'shared'>>;
17
17
  };
18
18
  export type LegacyAppTools = {
19
19
  hooks: AppToolsHooks;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-nightly-20240304170717",
18
+ "version": "0.0.0-nightly-20240306170726",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -69,37 +69,37 @@
69
69
  "@babel/parser": "^7.22.15",
70
70
  "@babel/traverse": "^7.23.2",
71
71
  "@babel/types": "^7.23.0",
72
- "@rsbuild/plugin-esbuild": "0.4.8",
73
- "@rsbuild/plugin-node-polyfill": "0.4.8",
74
- "@rsbuild/shared": "0.4.8",
75
- "@rsbuild/core": "0.4.8",
72
+ "@rsbuild/plugin-esbuild": "0.4.11",
73
+ "@rsbuild/plugin-node-polyfill": "0.4.11",
74
+ "@rsbuild/shared": "0.4.11",
75
+ "@rsbuild/core": "0.4.11",
76
76
  "es-module-lexer": "^1.1.0",
77
77
  "esbuild": "0.17.19",
78
78
  "@swc/helpers": "0.5.3",
79
- "@modern-js/uni-builder": "0.0.0-nightly-20240304170717",
80
- "@modern-js/core": "0.0.0-nightly-20240304170717",
81
- "@modern-js/plugin": "0.0.0-nightly-20240304170717",
82
- "@modern-js/plugin-data-loader": "0.0.0-nightly-20240304170717",
83
- "@modern-js/plugin-i18n": "0.0.0-nightly-20240304170717",
84
- "@modern-js/plugin-lint": "0.0.0-nightly-20240304170717",
85
- "@modern-js/prod-server": "0.0.0-nightly-20240304170717",
86
- "@modern-js/node-bundle-require": "0.0.0-nightly-20240304170717",
87
- "@modern-js/server": "0.0.0-nightly-20240304170717",
88
- "@modern-js/types": "0.0.0-nightly-20240304170717",
89
- "@modern-js/server-utils": "0.0.0-nightly-20240304170717",
90
- "@modern-js/utils": "0.0.0-nightly-20240304170717",
91
- "@modern-js/server-core": "0.0.0-nightly-20240304170717"
79
+ "@modern-js/uni-builder": "0.0.0-nightly-20240306170726",
80
+ "@modern-js/core": "0.0.0-nightly-20240306170726",
81
+ "@modern-js/node-bundle-require": "0.0.0-nightly-20240306170726",
82
+ "@modern-js/plugin": "0.0.0-nightly-20240306170726",
83
+ "@modern-js/plugin-data-loader": "0.0.0-nightly-20240306170726",
84
+ "@modern-js/plugin-i18n": "0.0.0-nightly-20240306170726",
85
+ "@modern-js/plugin-lint": "0.0.0-nightly-20240306170726",
86
+ "@modern-js/types": "0.0.0-nightly-20240306170726",
87
+ "@modern-js/server": "0.0.0-nightly-20240306170726",
88
+ "@modern-js/server-utils": "0.0.0-nightly-20240306170726",
89
+ "@modern-js/prod-server": "0.0.0-nightly-20240306170726",
90
+ "@modern-js/utils": "0.0.0-nightly-20240306170726",
91
+ "@modern-js/server-core": "0.0.0-nightly-20240306170726"
92
92
  },
93
93
  "devDependencies": {
94
- "@rsbuild/plugin-swc": "0.4.8",
94
+ "@rsbuild/plugin-swc": "0.4.11",
95
95
  "@types/babel__traverse": "7.18.5",
96
96
  "@types/jest": "^29",
97
97
  "@types/node": "^14",
98
98
  "jest": "^29",
99
99
  "typescript": "^5",
100
100
  "webpack": "^5.89.0",
101
- "@scripts/build": "0.0.0-nightly-20240304170717",
102
- "@scripts/jest-config": "0.0.0-nightly-20240304170717"
101
+ "@scripts/build": "0.0.0-nightly-20240306170726",
102
+ "@scripts/jest-config": "0.0.0-nightly-20240306170726"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {