@modern-js/plugin-swc 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/package.json +10 -10
  3. package/dist/bin.d.ts +0 -2
  4. package/dist/bin.js +0 -38
  5. package/dist/config/createLoadedConfig.d.ts +0 -6
  6. package/dist/config/createLoadedConfig.js +0 -35
  7. package/dist/config/createResolvedConfig.d.ts +0 -3
  8. package/dist/config/createResolvedConfig.js +0 -91
  9. package/dist/config/defaults.d.ts +0 -29
  10. package/dist/config/defaults.js +0 -110
  11. package/dist/config/index.d.ts +0 -2
  12. package/dist/config/index.js +0 -18
  13. package/dist/config/mergeConfig.d.ts +0 -32
  14. package/dist/config/mergeConfig.js +0 -39
  15. package/dist/config/schema/deploy.d.ts +0 -16
  16. package/dist/config/schema/deploy.js +0 -16
  17. package/dist/config/schema/index.d.ts +0 -499
  18. package/dist/config/schema/index.js +0 -94
  19. package/dist/config/schema/output.d.ts +0 -146
  20. package/dist/config/schema/output.js +0 -68
  21. package/dist/config/schema/server.d.ts +0 -194
  22. package/dist/config/schema/server.js +0 -111
  23. package/dist/config/schema/source.d.ts +0 -64
  24. package/dist/config/schema/source.js +0 -38
  25. package/dist/config/schema/tools.d.ts +0 -51
  26. package/dist/config/schema/tools.js +0 -24
  27. package/dist/config/types/electron.d.ts +0 -13
  28. package/dist/config/types/electron.js +0 -2
  29. package/dist/config/types/index.d.ts +0 -260
  30. package/dist/config/types/index.js +0 -2
  31. package/dist/config/types/less.d.ts +0 -12
  32. package/dist/config/types/less.js +0 -2
  33. package/dist/config/types/postcss.d.ts +0 -28
  34. package/dist/config/types/postcss.js +0 -2
  35. package/dist/config/types/sass.d.ts +0 -10
  36. package/dist/config/types/sass.js +0 -2
  37. package/dist/config/types/ssg.d.ts +0 -15
  38. package/dist/config/types/ssg.js +0 -2
  39. package/dist/config/types/test.d.ts +0 -14
  40. package/dist/config/types/test.js +0 -2
  41. package/dist/config/types/ts-loader.d.ts +0 -23
  42. package/dist/config/types/ts-loader.js +0 -2
  43. package/dist/context.d.ts +0 -34
  44. package/dist/context.js +0 -60
  45. package/dist/initWatcher.d.ts +0 -3
  46. package/dist/initWatcher.js +0 -66
  47. package/dist/load-configs/index.d.ts +0 -34
  48. package/dist/load-configs/index.js +0 -124
  49. package/dist/loadEnv.d.ts +0 -1
  50. package/dist/loadEnv.js +0 -21
  51. package/dist/loadPlugins.d.ts +0 -16
  52. package/dist/loadPlugins.js +0 -60
  53. package/dist/manager.d.ts +0 -87
  54. package/dist/manager.js +0 -24
  55. package/dist/pluginAPI.d.ts +0 -13
  56. package/dist/pluginAPI.js +0 -16
  57. package/dist/schema/patchSchema.d.ts +0 -19
  58. package/dist/schema/patchSchema.js +0 -57
  59. package/dist/schema/source.d.ts +0 -9
  60. package/dist/schema/source.js +0 -10
  61. package/dist/schema/testing.d.ts +0 -13
  62. package/dist/schema/testing.js +0 -11
  63. package/dist/schema/traverseSchema.d.ts +0 -2
  64. package/dist/schema/traverseSchema.js +0 -20
  65. package/dist/types/cli.d.ts +0 -59
  66. package/dist/types/cli.js +0 -2
  67. package/dist/types/config/index.d.ts +0 -41
  68. package/dist/types/config/index.js +0 -2
  69. package/dist/types/config/testing.d.ts +0 -15
  70. package/dist/types/config/testing.js +0 -2
  71. package/dist/types/context.d.ts +0 -26
  72. package/dist/types/context.js +0 -2
  73. package/dist/types/hooks.d.ts +0 -26
  74. package/dist/types/hooks.js +0 -2
  75. package/dist/types/index.d.ts +0 -10
  76. package/dist/types/index.js +0 -21
  77. package/dist/types/plugin.d.ts +0 -26
  78. package/dist/types/plugin.js +0 -2
  79. package/dist/types/pluginAPI.d.ts +0 -18
  80. package/dist/types/pluginAPI.js +0 -2
  81. package/dist/utils/commander.d.ts +0 -4
  82. package/dist/utils/commander.js +0 -20
  83. package/dist/utils/mergeConfig.d.ts +0 -2
  84. package/dist/utils/mergeConfig.js +0 -32
  85. package/dist/utils/repeatKeyWarning.d.ts +0 -3
  86. package/dist/utils/repeatKeyWarning.js +0 -22
@@ -1,13 +0,0 @@
1
- import { TransformOptions } from '@babel/core';
2
- import { Configuration } from 'electron-builder';
3
- export declare type BuildConfig = {
4
- baseConfig: Configuration;
5
- macConfig?: Configuration;
6
- winConfig?: Configuration;
7
- win64Config?: Configuration;
8
- linuxConfig?: Configuration;
9
- };
10
- export declare type ElectronConfig = {
11
- builder?: BuildConfig;
12
- babel?: TransformOptions | ((defaultBabelConfig: TransformOptions) => TransformOptions);
13
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,260 +0,0 @@
1
- import type { DevServerHttpsOptions, DevServerOptions } from '@modern-js/types';
2
- import type { AliasOption, MetaOptions, ChainIdentifier, WatchOptions } from '@modern-js/utils';
3
- import type { BabelConfig } from '@modern-js/babel-preset-app';
4
- import type webpack from 'webpack';
5
- import type { RuleSetRule, Configuration as WebpackConfiguration, WebpackPluginInstance } from 'webpack';
6
- import type WebpackChain from '@modern-js/utils/webpack-chain';
7
- import type autoprefixer from 'autoprefixer';
8
- import type { BasePluginOptions, TerserOptions as RawTerserOptions } from 'terser-webpack-plugin';
9
- import type { AcceptedPlugin as PostCSSPlugin } from 'postcss';
10
- import { TransformOptions } from '@babel/core';
11
- import type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
12
- import type { PluginConfig, NewPluginConfig } from '../../loadPlugins';
13
- import type { TestConfig, JestConfig } from './test';
14
- import type { SassConfig, SassLoaderOptions } from './sass';
15
- import type { LessConfig, LessLoaderOptions } from './less';
16
- import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
17
- import type { ElectronConfig } from './electron';
18
- import type { PostCSSLoaderOptions } from './postcss';
19
- import type { TsLoaderOptions } from './ts-loader';
20
- declare type AutoprefixerOptions = autoprefixer.Options;
21
- declare type TerserOptions = BasePluginOptions & {
22
- terserOptions?: Partial<RawTerserOptions>;
23
- };
24
- export type { TestConfig, JestConfig, BabelConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions, PluginConfig, NewPluginConfig, };
25
- export interface SourceConfig {
26
- entries?: Record<string, string | {
27
- entry: string;
28
- enableFileSystemRoutes?: boolean;
29
- disableMount?: boolean;
30
- }>;
31
- preEntry?: string | string[];
32
- enableAsyncEntry?: boolean;
33
- disableDefaultEntries?: boolean;
34
- entriesDir?: string;
35
- configDir?: string;
36
- apiDir?: string;
37
- envVars?: Array<string>;
38
- globalVars?: Record<string, string>;
39
- alias?: AliasOption;
40
- moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
41
- include?: Array<string | RegExp>;
42
- /**
43
- * The configuration of `source.designSystem` is provided by `tailwindcss` plugin.
44
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
45
- * @requires `tailwindcss` plugin
46
- */
47
- designSystem?: Record<string, any>;
48
- }
49
- export interface OutputConfig {
50
- assetPrefix?: string;
51
- htmlPath?: string;
52
- jsPath?: string;
53
- cssPath?: string;
54
- mediaPath?: string;
55
- path?: string;
56
- title?: string;
57
- titleByEntries?: Record<string, string>;
58
- meta?: MetaOptions;
59
- metaByEntries?: Record<string, MetaOptions>;
60
- inject?: 'body' | 'head' | boolean;
61
- injectByEntries?: Record<string, 'body' | 'head' | boolean>;
62
- mountId?: string;
63
- favicon?: string;
64
- faviconByEntries?: Record<string, string | undefined>;
65
- copy?: Array<Record<string, unknown> & {
66
- from: string;
67
- }>;
68
- scriptExt?: Record<string, unknown>;
69
- disableTsChecker?: boolean;
70
- disableHtmlFolder?: boolean;
71
- disableCssModuleExtension?: boolean;
72
- disableCssExtract?: boolean;
73
- enableCssModuleTSDeclaration?: boolean;
74
- disableMinimize?: boolean;
75
- enableInlineStyles?: boolean;
76
- enableInlineScripts?: boolean;
77
- disableSourceMap?: boolean;
78
- disableInlineRuntimeChunk?: boolean;
79
- disableAssetsCache?: boolean;
80
- enableLatestDecorators?: boolean;
81
- polyfill?: 'off' | 'usage' | 'entry' | 'ua';
82
- dataUriLimit?: number;
83
- templateParameters?: Record<string, unknown>;
84
- templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
85
- cssModuleLocalIdentName?: string;
86
- enableModernMode?: boolean;
87
- federation?: boolean;
88
- disableNodePolyfill?: boolean;
89
- enableTsLoader?: boolean;
90
- /**
91
- * The configuration of `output.ssg` is provided by `ssg` plugin.
92
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
93
- * @requires `ssg` plugin
94
- */
95
- ssg?: SSGConfig;
96
- }
97
- export interface ServerConfig {
98
- routes?: Record<string, string | string[] | {
99
- route?: string | string[];
100
- disableSpa?: boolean;
101
- resHeaders?: Record<string, unknown>;
102
- }>;
103
- publicRoutes?: {
104
- [filepath: string]: string;
105
- };
106
- ssr?: boolean | {
107
- mode?: 'string' | 'stream';
108
- [property: string]: unknown;
109
- };
110
- ssrByEntries?: Record<string, boolean | {
111
- mode?: 'string' | 'stream';
112
- [property: string]: unknown;
113
- }>;
114
- baseUrl?: string | Array<string>;
115
- port?: number;
116
- logger?: boolean | Record<string, any>;
117
- metrics?: boolean | Record<string, any>;
118
- enableMicroFrontendDebug?: boolean;
119
- watchOptions?: WatchOptions;
120
- compiler?: 'babel' | 'typescript';
121
- disableFrameworkExt?: boolean;
122
- }
123
- export declare type DevProxyOptions = string | Record<string, string>;
124
- export interface DevConfig {
125
- assetPrefix?: string | boolean;
126
- https?: DevServerHttpsOptions;
127
- /**
128
- * The configuration of `dev.proxy` is provided by `proxy` plugin.
129
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
130
- * @requires `proxy` plugin
131
- */
132
- proxy?: DevProxyOptions;
133
- }
134
- export interface MicroFrontend {
135
- enableHtmlEntry?: boolean;
136
- externalBasicLibrary?: boolean;
137
- moduleApp?: string;
138
- }
139
- export interface DeployConfig {
140
- microFrontend?: boolean | MicroFrontend;
141
- domain?: string | Array<string>;
142
- domainByEntries?: Record<string, string | Array<string>>;
143
- }
144
- declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>, utils?: any) => Record<string, unknown> | void);
145
- export declare type PostCSSConfigUtils = {
146
- addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void;
147
- };
148
- export declare type PostCSSConfig = PostCSSLoaderOptions | ((options: PostCSSLoaderOptions, utils: PostCSSConfigUtils) => PostCSSLoaderOptions | void);
149
- export declare type WebpackConfigUtils = {
150
- env: string;
151
- /** @deprecated Use target instead */
152
- name: string;
153
- target: string;
154
- webpack: typeof webpack;
155
- HtmlWebpackPlugin: typeof import('html-webpack-plugin');
156
- addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
157
- prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
158
- appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
159
- removePlugin: (pluginName: string) => void;
160
- };
161
- export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils: WebpackConfigUtils) => WebpackConfiguration | void);
162
- export declare type WebpackChainConfigUtils = {
163
- env: string;
164
- /** @deprecated Use target instead */
165
- name: string;
166
- target: string;
167
- webpack: typeof webpack;
168
- CHAIN_ID: ChainIdentifier;
169
- HtmlWebpackPlugin: typeof import('html-webpack-plugin');
170
- };
171
- export declare type WebpackChainConfig = (chain: WebpackChain, utils: WebpackChainConfigUtils) => void;
172
- export declare type TsLoaderConfigUtils = {
173
- addIncludes: (includes: string | RegExp | (string | RegExp)[]) => void;
174
- addExcludes: (excludes: string | RegExp | (string | RegExp)[]) => void;
175
- };
176
- export declare type TsLoaderConfig = TsLoaderOptions | ((config: TsLoaderOptions, utils: TsLoaderConfigUtils) => TsLoaderOptions | void);
177
- export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
178
- export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
179
- export declare type HtmlPluginConfig = HTMLPluginOptions | ((options: HTMLPluginOptions, entryInfo: {
180
- entryName: string;
181
- entryValue: webpack.Configuration['entry'];
182
- }) => HTMLPluginOptions | void);
183
- export interface ToolsConfig {
184
- webpack?: WebpackConfig;
185
- webpackChain?: WebpackChainConfig;
186
- babel?: BabelConfig;
187
- autoprefixer?: AutoprefixerConfig;
188
- postcss?: PostCSSConfig;
189
- styledComponents?: ConfigFunction;
190
- lodash?: ConfigFunction;
191
- devServer?: DevServerOptions;
192
- tsLoader?: TsLoaderConfig;
193
- terser?: TerserConfig;
194
- minifyCss?: ConfigFunction;
195
- esbuild?: Record<string, unknown>;
196
- htmlPlugin?: HtmlPluginConfig;
197
- /**
198
- * The configuration of `tools.tailwindcss` is provided by `tailwindcss` plugin.
199
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
200
- * @requires `tailwindcss` plugin
201
- */
202
- tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
203
- /**
204
- * The configuration of `tools.jest` is provided by `testing` plugin.
205
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
206
- * @requires `testing` plugin
207
- */
208
- jest?: TestConfig['jest'];
209
- sass?: SassConfig;
210
- less?: LessConfig;
211
- }
212
- export interface RuntimeConfig {
213
- [name: string]: any;
214
- }
215
- export interface RuntimeByEntriesConfig {
216
- [name: string]: RuntimeConfig;
217
- }
218
- export interface BffConfig {
219
- prefix?: string;
220
- requestCreator?: string;
221
- fetcher?: string;
222
- proxy?: Record<string, any>;
223
- }
224
- export interface UserConfig {
225
- source?: SourceConfig;
226
- output?: OutputConfig;
227
- server?: ServerConfig;
228
- dev?: DevConfig;
229
- deploy?: DeployConfig;
230
- tools?: ToolsConfig;
231
- plugins?: PluginConfig;
232
- runtime?: RuntimeConfig;
233
- runtimeByEntries?: RuntimeByEntriesConfig;
234
- /**
235
- * The configuration of `bff` is provided by `bff` plugin.
236
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
237
- * @requires `bff` plugin
238
- */
239
- bff?: BffConfig;
240
- /**
241
- * The configuration of `testing` is provided by `testing` plugin.
242
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
243
- * @requires `testing` plugin
244
- */
245
- testing?: TestConfig;
246
- /**
247
- * The configuration of `electron` is provided by `electron` plugin.
248
- * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
249
- * @requires `electron` plugin
250
- */
251
- electron?: ElectronConfig;
252
- }
253
- export declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
254
- export interface LoadedConfig {
255
- config: UserConfig;
256
- filePath: string | false;
257
- dependencies: string[];
258
- pkgConfig: UserConfig;
259
- jsConfig: UserConfig;
260
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +0,0 @@
1
- /// <reference types="less" />
2
- import type { LoaderContext } from 'webpack';
3
- export declare type LessLoaderOptions = {
4
- lessOptions?: Less.Options;
5
- additionalData?: string | ((content: string, loaderContext: LoaderContext<LessLoaderOptions>) => string);
6
- sourceMap?: boolean;
7
- webpackImporter?: boolean;
8
- implementation?: boolean;
9
- };
10
- export declare type LessConfig = LessLoaderOptions | ((options: LessLoaderOptions, utils: {
11
- addExcludes: (excludes: RegExp | RegExp[]) => void;
12
- }) => LessLoaderOptions | void);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,28 +0,0 @@
1
- import type { Syntax, Parser, Stringifier, AcceptedPlugin, SourceMapOptions } from 'postcss';
2
- export declare type PostCSSOptions = {
3
- to?: string;
4
- from?: string;
5
- map?: boolean | SourceMapOptions;
6
- syntax?: Syntax;
7
- parser?: string | object | (() => Parser);
8
- plugins?: AcceptedPlugin[];
9
- stringifier?: Stringifier | Syntax;
10
- };
11
- export declare type PostCSSLoaderOptions = {
12
- /**
13
- * Enable PostCSS Parser support in CSS-in-JS. If you use JS styles the postcss-js parser, add the execute option.
14
- */
15
- execute?: boolean;
16
- /**
17
- * By default generation of source maps depends on the devtool option. All values enable source map generation except eval and false value.
18
- */
19
- sourceMap?: boolean;
20
- /**
21
- * The special implementation option determines which implementation of PostCSS to use.
22
- */
23
- implementation?: unknown;
24
- /**
25
- * Allows to set PostCSS options and plugins.
26
- */
27
- postcssOptions?: PostCSSOptions;
28
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import type { LegacyFileOptions } from 'sass';
2
- export interface SassLoaderOptions {
3
- sassOptions?: LegacyFileOptions<'sync'>;
4
- sourceMap?: boolean;
5
- implementation?: string;
6
- additionalData?: string | ((content: string, filename: string) => string);
7
- }
8
- export declare type SassConfig = SassLoaderOptions | ((options: SassLoaderOptions, utils: {
9
- addExcludes: (excludes: RegExp | RegExp[]) => void;
10
- }) => SassLoaderOptions | void);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +0,0 @@
1
- export declare type SSGRouteOptions = string | {
2
- url: string;
3
- output?: string;
4
- params?: Record<string, any>[];
5
- headers?: Record<string, any>;
6
- };
7
- export declare type SSGSingleEntryOptions = boolean | {
8
- preventDefault?: string[];
9
- headers?: Record<string, any>;
10
- routes?: SSGRouteOptions[];
11
- };
12
- export declare type SSGMultiEntryOptions = Record<string, SSGSingleEntryOptions>;
13
- export declare type SSGConfig = boolean | SSGSingleEntryOptions | SSGMultiEntryOptions | ((entryName: string, payload: {
14
- baseUrl?: string;
15
- }) => SSGSingleEntryOptions);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +0,0 @@
1
- import type { Config as JestConfigTypes } from '@jest/types';
2
- export declare type JestConfig = JestConfigTypes.InitialOptions;
3
- export interface TestConfig {
4
- /**
5
- * Decide which transformer will be used to compile file
6
- * Default: babel-jest
7
- */
8
- transformer?: 'babel-jest' | 'ts-jest';
9
- /**
10
- * Original jest config
11
- * Doc: https://jestjs.io/docs/configuration
12
- */
13
- jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
14
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +0,0 @@
1
- export declare type TsLoaderOptions = {
2
- colors?: boolean;
3
- silent?: boolean;
4
- context?: string;
5
- instance?: string;
6
- logLevel?: string;
7
- compiler?: string;
8
- configFile?: string;
9
- reportFiles?: string[];
10
- transpileOnly?: boolean;
11
- happyPackMode?: boolean;
12
- errorFormatter?: (message: Record<string, unknown>, colors: boolean) => string;
13
- logInfoToStdOut?: boolean;
14
- compilerOptions?: Record<string, unknown>;
15
- appendTsSuffixTo?: (RegExp | string)[];
16
- appendTsxSuffixTo?: (RegExp | string)[];
17
- projectReferences?: boolean;
18
- ignoreDiagnostics?: number[];
19
- allowTsInNodeModules?: boolean;
20
- experimentalFileCaching?: boolean;
21
- onlyCompileBundledFiles?: boolean;
22
- useCaseSensitiveFileNames?: boolean;
23
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/context.d.ts DELETED
@@ -1,34 +0,0 @@
1
- import type { CliPlugin, UserConfig, IAppContext, InternalPlugins, NormalizedConfig } from './types';
2
- export declare const AppContext: import("@modern-js/plugin").Context<IAppContext>;
3
- export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig<any, {}, {}, {}>>;
4
- export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig<any, {}, {}, {}>>;
5
- /**
6
- * Set app context.
7
- * @param value new app context. It will override previous app context.
8
- */
9
- export declare const setAppContext: (value: IAppContext) => void;
10
- /**
11
- * Get app context, including directories, plugins and some static infos.
12
- */
13
- export declare const useAppContext: () => IAppContext;
14
- /**
15
- * Get original content of user config.
16
- */
17
- export declare const useConfigContext: <Extends extends Record<string, any>>() => UserConfig<Extends>;
18
- /**
19
- * Get normalized content of user config.
20
- */
21
- export declare const useResolvedConfigContext: <Extends extends Record<string, any>>() => NormalizedConfig<Extends>;
22
- export declare const initAppContext: ({ appDirectory, plugins, configFile, options, serverConfigFile, serverInternalPlugins, }: {
23
- appDirectory: string;
24
- plugins: CliPlugin[];
25
- configFile: string | false;
26
- options?: {
27
- metaName?: string | undefined;
28
- srcDir?: string | undefined;
29
- distDir?: string | undefined;
30
- sharedDir?: string | undefined;
31
- } | undefined;
32
- serverConfigFile: string;
33
- serverInternalPlugins: InternalPlugins;
34
- }) => IAppContext;
package/dist/context.js DELETED
@@ -1,60 +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
- exports.initAppContext = exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const utils_1 = require("@modern-js/utils");
9
- const plugin_1 = require("@modern-js/plugin");
10
- exports.AppContext = (0, plugin_1.createContext)({});
11
- exports.ConfigContext = (0, plugin_1.createContext)({});
12
- exports.ResolvedConfigContext = (0, plugin_1.createContext)({});
13
- /**
14
- * Set app context.
15
- * @param value new app context. It will override previous app context.
16
- */
17
- const setAppContext = (value) => exports.AppContext.set(value);
18
- exports.setAppContext = setAppContext;
19
- /**
20
- * Get app context, including directories, plugins and some static infos.
21
- */
22
- const useAppContext = () => exports.AppContext.use().value;
23
- exports.useAppContext = useAppContext;
24
- /**
25
- * Get original content of user config.
26
- */
27
- const useConfigContext = () => exports.ConfigContext.use().value;
28
- exports.useConfigContext = useConfigContext;
29
- /**
30
- * Get normalized content of user config.
31
- */
32
- const useResolvedConfigContext = () => exports.ResolvedConfigContext.use().value;
33
- exports.useResolvedConfigContext = useResolvedConfigContext;
34
- const initAppContext = ({ appDirectory, plugins, configFile, options, serverConfigFile, serverInternalPlugins, }) => {
35
- const { metaName = 'modern-js', srcDir = 'src', distDir = '', sharedDir = 'shared', } = options || {};
36
- return {
37
- metaName,
38
- appDirectory,
39
- configFile,
40
- serverConfigFile,
41
- serverInternalPlugins,
42
- ip: utils_1.address.ip(),
43
- port: 0,
44
- packageName: require(path_1.default.resolve(appDirectory, './package.json')).name,
45
- srcDirectory: path_1.default.resolve(appDirectory, srcDir),
46
- distDirectory: distDir,
47
- sharedDirectory: path_1.default.resolve(appDirectory, sharedDir),
48
- nodeModulesDirectory: path_1.default.resolve(appDirectory, './node_modules'),
49
- internalDirectory: path_1.default.resolve(appDirectory, `./node_modules/.${metaName}`),
50
- plugins,
51
- htmlTemplates: {},
52
- serverRoutes: [],
53
- entrypoints: [],
54
- checkedEntries: [],
55
- apiOnly: false,
56
- internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
57
- internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`,
58
- };
59
- };
60
- exports.initAppContext = initAppContext;
@@ -1,3 +0,0 @@
1
- import { LoadedConfig } from './config';
2
- import { HooksRunner } from './manager';
3
- export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<import("@modern-js/utils").FSWatcher | undefined>;
@@ -1,66 +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
- exports.initWatcher = void 0;
7
- const crypto_1 = __importDefault(require("crypto"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const utils_1 = require("@modern-js/utils");
11
- const debug = (0, utils_1.createDebugger)('watch-files');
12
- const md5 = (data) => crypto_1.default.createHash('md5').update(data).digest('hex');
13
- const hashMap = new Map();
14
- const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
15
- // only add fs watcher on dev mode.
16
- if (((0, utils_1.isDev)() || (0, utils_1.isTest)()) && argv[0] === 'dev') {
17
- const extraFiles = await hooksRunner.watchFiles();
18
- const configPath = path_1.default.join(appDirectory, configDir);
19
- const watched = [
20
- `${configPath}/html`,
21
- ...extraFiles,
22
- loaded === null || loaded === void 0 ? void 0 : loaded.filePath,
23
- ...loaded.dependencies,
24
- ].filter(Boolean);
25
- debug(`watched: %o`, watched);
26
- const watcher = utils_1.chokidar.watch(watched, {
27
- cwd: appDirectory,
28
- ignoreInitial: true,
29
- ignorePermissionErrors: true,
30
- ignored: [
31
- /node_modules/,
32
- '**/__test__/**',
33
- '**/*.test.(js|jsx|ts|tsx)',
34
- '**/*.spec.(js|jsx|ts|tsx)',
35
- '**/*.stories.(js|jsx|ts|tsx)',
36
- ],
37
- });
38
- watcher.on('change', changed => {
39
- const lastHash = hashMap.get(changed);
40
- const currentHash = md5(fs_1.default.readFileSync(path_1.default.join(appDirectory, changed), 'utf8'));
41
- if (currentHash !== lastHash) {
42
- debug(`file change: %s`, changed);
43
- hashMap.set(changed, currentHash);
44
- hooksRunner.fileChange({ filename: changed, eventType: 'change' });
45
- }
46
- });
47
- watcher.on('add', name => {
48
- debug(`add file: %s`, name);
49
- const currentHash = md5(fs_1.default.readFileSync(path_1.default.join(appDirectory, name), 'utf8'));
50
- hashMap.set(name, currentHash);
51
- hooksRunner.fileChange({ filename: name, eventType: 'add' });
52
- });
53
- watcher.on('unlink', name => {
54
- debug(`remove file: %s`, name);
55
- if (hashMap.has(name)) {
56
- hashMap.delete(name);
57
- }
58
- hooksRunner.fileChange({ filename: name, eventType: 'unlink' });
59
- });
60
- watcher.on('error', err => {
61
- throw err;
62
- });
63
- return watcher;
64
- }
65
- };
66
- exports.initWatcher = initWatcher;
@@ -1,34 +0,0 @@
1
- import path from 'path';
2
- export declare const CONFIG_FILE_NAME = "modern.config";
3
- export declare const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
4
- /**
5
- * Get user config from package.json.
6
- * @param appDirectory - App root directory.
7
- * @returns modernConfig or undefined
8
- */
9
- export declare const getPackageConfig: <T>(appDirectory: string, packageJsonConfig?: string) => T | undefined;
10
- /**
11
- * Get the file dependencies by module.children, ignore file path in node_modules and this monorepo packages default.
12
- * @param filePath - Absolute file path.
13
- * @returns File dependencies array.
14
- */
15
- export declare const getDependencies: (filePath: string) => string[];
16
- /**
17
- *
18
- * @param targetDir target dir
19
- * @param overtime Unit of second
20
- */
21
- export declare const clearFilesOverTime: (targetDir: string, overtime: number) => Promise<void>;
22
- export declare const getConfigFilePath: (appDirectory: string, filePath?: string) => string | false;
23
- /**
24
- * Parse and load user config file, support extensions like .ts, mjs, js, ejs.
25
- * @param appDirectory - App root directory, from which start search user config file.
26
- * @param filePath - Specific absolute config file path.
27
- * @returns Object contain config file path, user config object and dependency files used by config file.
28
- */
29
- export declare const loadConfig: <T>(appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<{
30
- path: string | false;
31
- config?: T | undefined;
32
- dependencies?: string[] | undefined;
33
- pkgConfig?: T | undefined;
34
- }>;