@modern-js/module-tools 1.4.1 → 1.4.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 (66) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/js/modern/cli/build.js +2 -2
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/commands/build.js +5 -6
  5. package/dist/js/modern/commands/dev.js +6 -7
  6. package/dist/js/modern/features/build/build-platform.js +3 -3
  7. package/dist/js/modern/features/build/build-watch.js +5 -6
  8. package/dist/js/modern/features/build/build.js +5 -6
  9. package/dist/js/modern/features/build/index.js +5 -5
  10. package/dist/js/modern/features/build/utils.js +9 -10
  11. package/dist/js/modern/features/dev/index.js +9 -7
  12. package/dist/js/modern/hooks/build.js +20 -0
  13. package/dist/js/modern/hooks/dev.js +11 -0
  14. package/dist/js/modern/hooks/index.js +14 -0
  15. package/dist/js/modern/index.js +37 -37
  16. package/dist/js/modern/tasks/build-source-code.js +2 -1
  17. package/dist/js/modern/tasks/build-style.js +1 -1
  18. package/dist/js/modern/tasks/build-watch-source-code.js +2 -1
  19. package/dist/js/modern/tasks/build-watch-style.js +1 -1
  20. package/dist/js/modern/tasks/generator-dts/index.js +8 -10
  21. package/dist/js/modern/tasks/generator-dts/utils.js +9 -0
  22. package/dist/js/modern/utils/babel.js +12 -22
  23. package/dist/js/node/cli/build.js +2 -2
  24. package/dist/js/node/cli/dev.js +2 -2
  25. package/dist/js/node/commands/build.js +5 -7
  26. package/dist/js/node/commands/dev.js +6 -8
  27. package/dist/js/node/features/build/build-platform.js +3 -4
  28. package/dist/js/node/features/build/build-watch.js +5 -7
  29. package/dist/js/node/features/build/build.js +5 -7
  30. package/dist/js/node/features/build/index.js +5 -5
  31. package/dist/js/node/features/build/utils.js +9 -11
  32. package/dist/js/node/features/dev/index.js +9 -8
  33. package/dist/js/node/hooks/build.js +37 -0
  34. package/dist/js/node/hooks/dev.js +25 -0
  35. package/dist/js/node/hooks/index.js +39 -0
  36. package/dist/js/node/index.js +50 -42
  37. package/dist/js/node/tasks/build-source-code.js +2 -1
  38. package/dist/js/node/tasks/build-style.js +1 -1
  39. package/dist/js/node/tasks/build-watch-source-code.js +2 -1
  40. package/dist/js/node/tasks/build-watch-style.js +1 -1
  41. package/dist/js/node/tasks/generator-dts/index.js +7 -13
  42. package/dist/js/node/tasks/generator-dts/utils.js +14 -2
  43. package/dist/js/node/utils/babel.js +10 -20
  44. package/dist/types/cli/build.d.ts +2 -1
  45. package/dist/types/cli/dev.d.ts +2 -1
  46. package/dist/types/commands/build.d.ts +2 -1
  47. package/dist/types/commands/dev.d.ts +2 -1
  48. package/dist/types/features/build/build-platform.d.ts +2 -1
  49. package/dist/types/features/build/build-watch.d.ts +2 -2
  50. package/dist/types/features/build/build.d.ts +2 -2
  51. package/dist/types/features/build/index.d.ts +2 -2
  52. package/dist/types/features/build/utils.d.ts +4 -3
  53. package/dist/types/features/dev/index.d.ts +4 -3
  54. package/dist/types/hooks/build.d.ts +46 -0
  55. package/dist/types/hooks/dev.d.ts +18 -0
  56. package/dist/types/hooks/index.d.ts +26 -0
  57. package/dist/types/index.d.ts +3 -19
  58. package/dist/types/tasks/generator-dts/utils.d.ts +2 -1
  59. package/dist/types/utils/babel.d.ts +1 -2
  60. package/jest.config.js +0 -3
  61. package/lib/types.d.ts +92 -0
  62. package/package.json +19 -20
  63. package/tests/dev-cli.test.ts +42 -8
  64. package/tests/dev-command.test.ts +36 -10
  65. package/tests/dev-feature.test.ts +45 -13
  66. package/tests/generate-dts.test.ts +9 -0
@@ -78,7 +78,8 @@ const runBabelCompiler = async (config, modernConfig) => {
78
78
  rootDir: config.srcRootDir,
79
79
  distDir: config.distDir,
80
80
  watchDir: config.srcRootDir,
81
- extensions: getExts(isTs)
81
+ extensions: getExts(isTs),
82
+ ignore: ['*.d.ts']
82
83
  }, _objectSpread(_objectSpread({}, babelConfig), {}, {
83
84
  sourceMaps: config.sourceMaps
84
85
  }));
@@ -13,7 +13,7 @@ const logger = _utils.Import.lazy('../features/build/logger', require);
13
13
 
14
14
  const cssConfig = _utils.Import.lazy('@modern-js/css-config', require);
15
15
 
16
- const hooks = _utils.Import.lazy('@modern-js/module-tools-hooks', require);
16
+ const hooks = _utils.Import.lazy('../hooks', require);
17
17
 
18
18
  const core = _utils.Import.lazy('@modern-js/core', require);
19
19
 
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
 
3
- var path = _interopRequireWildcard(require("path"));
4
-
5
3
  var _utils = require("@modern-js/utils");
6
4
 
7
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
8
-
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
5
+ var _utils2 = require("./utils");
10
6
 
11
7
  const core = _utils.Import.lazy('@modern-js/core', require);
12
8
 
@@ -75,7 +71,7 @@ const generatorDts = async (_, config) => {
75
71
  sourceDir: sourceDirName
76
72
  });
77
73
  removeTsconfigPath = willDeleteTsconfigPath;
78
- const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
74
+ const tscBinFile = (0, _utils2.getTscBinPath)(appDirectory);
79
75
  const watchParams = watch ? ['-w'] : [];
80
76
  const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
81
77
  stdio: 'pipe',
@@ -88,17 +84,15 @@ const generatorDts = async (_, config) => {
88
84
 
89
85
  try {
90
86
  await childProgress;
91
- console.info('[Tsc Compiler]: Successfully');
87
+ console.info('[TSC Compiler]: Successfully');
92
88
  } catch (e) {
93
89
  if (!tsCheck) {
94
90
  console.info(`There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'`);
91
+ } // 通过使用 execa,可以将 tsc 的 data 类型的报错信息变为异常错误信息
92
+ else if ((0, _utils.isObject)(e) && e.stdout) {
93
+ console.error(e.stdout);
95
94
  } else {
96
- const isRecord = input => typeof input === 'object'; // 通过使用 execa,可以将tsc 的 data 类型的报错信息变为异常错误信息
97
-
98
-
99
- if (isRecord(e)) {
100
- console.error(e.stdout);
101
- }
95
+ console.error(e);
102
96
  }
103
97
  }
104
98
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.resolveAlias = exports.generatorTsConfig = void 0;
6
+ exports.resolveAlias = exports.getTscBinPath = exports.generatorTsConfig = void 0;
7
7
 
8
8
  var path = _interopRequireWildcard(require("path"));
9
9
 
@@ -105,4 +105,16 @@ const resolveAlias = (modernConfig, config, watchFilenames = []) => {
105
105
  }
106
106
  };
107
107
 
108
- exports.resolveAlias = resolveAlias;
108
+ exports.resolveAlias = resolveAlias;
109
+
110
+ const getTscBinPath = appDirectory => {
111
+ const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
112
+
113
+ if (!_utils.fs.existsSync(tscBinFile)) {
114
+ throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
115
+ }
116
+
117
+ return tscBinFile;
118
+ };
119
+
120
+ exports.getTscBinPath = getTscBinPath;
@@ -48,7 +48,8 @@ const resolveBabelConfig = (appDirectory, modernConfig, option) => {
48
48
  importStyle
49
49
  },
50
50
  tools: {
51
- lodash: userLodashOption
51
+ lodash: userLodashOption,
52
+ styledComponents
52
53
  }
53
54
  } = modernConfig; // alias config
54
55
 
@@ -70,32 +71,21 @@ const resolveBabelConfig = (appDirectory, modernConfig, option) => {
70
71
  globalVars,
71
72
  lodashOptions,
72
73
  jsxTransformRuntime,
73
- importStyle
74
+ importStyle,
75
+ styledComponentsOptions: (0, _utils.applyOptionsChain)({
76
+ pure: true,
77
+ displayName: true,
78
+ ssr: (0, _utils.isUseSSRBundle)(modernConfig),
79
+ transpileTemplateLiterals: true
80
+ }, styledComponents)
74
81
  }, {
75
82
  type: option.type,
76
83
  syntax: option.syntax
77
84
  }); // Preventing warning when files are too large
78
85
 
79
86
  internalBabelConfig.compact = false;
80
- const babelChain = (0, _babelPresetModule.getModuleBabelChain)({
81
- appDirectory,
82
- enableReactPreset: true,
83
- enableTypescriptPreset: true,
84
- alias: aliasConfig,
85
- envVars,
86
- globalVars,
87
- lodashOptions,
88
- jsxTransformRuntime,
89
- importStyle
90
- }, {
91
- type: option.type,
92
- syntax: option.syntax
93
- });
94
87
  const userBabelConfig = modernConfig.tools.babel;
95
- return (0, _utils.applyOptionsChain)(internalBabelConfig, // TODO: 感觉 userBabelConfig 的类型应该是TransformOptions
96
- userBabelConfig, {
97
- chain: babelChain
98
- });
88
+ return (0, _utils.applyOptionsChain)(internalBabelConfig, userBabelConfig);
99
89
  };
100
90
 
101
91
  exports.resolveBabelConfig = resolveBabelConfig;
@@ -1,2 +1,3 @@
1
1
  import type { Command } from 'commander';
2
- export declare const buildCli: (program: Command) => void;
2
+ import type { PluginAPI } from '@modern-js/core';
3
+ export declare const buildCli: (program: Command, api: PluginAPI) => void;
@@ -1,2 +1,3 @@
1
+ import type { PluginAPI } from '@modern-js/core';
1
2
  import type { Command } from 'commander';
2
- export declare const devCli: (program: Command) => void;
3
+ export declare const devCli: (program: Command, api: PluginAPI) => void;
@@ -1,3 +1,4 @@
1
+ import type { PluginAPI } from '@modern-js/core';
1
2
  import type { Platform } from '../types';
2
3
  export interface IBuildOption {
3
4
  watch: boolean;
@@ -7,7 +8,7 @@ export interface IBuildOption {
7
8
  tsc: boolean;
8
9
  clear: boolean;
9
10
  }
10
- export declare const build: ({
11
+ export declare const build: (api: PluginAPI, {
11
12
  watch,
12
13
  tsconfig: tsconfigName,
13
14
  tsc,
@@ -1,4 +1,5 @@
1
+ import type { PluginAPI } from '@modern-js/core';
1
2
  export interface IDevOption {
2
3
  tsconfig: string;
3
4
  }
4
- export declare const dev: (option: IDevOption, subCmd?: string) => Promise<void>;
5
+ export declare const dev: (api: PluginAPI, option: IDevOption, subCmd?: string) => Promise<void>;
@@ -1,6 +1,7 @@
1
+ import type { PluginAPI } from '@modern-js/core';
1
2
  export declare type Platform = 'all' | 'docs' | 'storybook';
2
3
  export interface IBuildPlatformOption {
3
4
  platform: Platform;
4
5
  isTsProject?: boolean;
5
6
  }
6
- export declare const buildPlatform: (option: IBuildPlatformOption) => Promise<void>;
7
+ export declare const buildPlatform: (api: PluginAPI, option: IBuildPlatformOption) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import type { NormalizedConfig } from '@modern-js/core';
1
+ import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
2
2
  import type { IBuildConfig } from '../../types';
3
- export declare const buildInWatchMode: (config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
3
+ export declare const buildInWatchMode: (api: PluginAPI, config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import type { NormalizedConfig } from '@modern-js/core';
1
+ import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
2
2
  import type { IBuildConfig } from '../../types';
3
- export declare const buildSourceCode: (config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
3
+ export declare const buildSourceCode: (api: PluginAPI, config: IBuildConfig, _: NormalizedConfig) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import type { NormalizedConfig } from '@modern-js/core';
1
+ import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
2
2
  import type { IBuildConfig } from '../../types';
3
- export declare const build: (config: IBuildConfig, modernConfig: NormalizedConfig) => Promise<void>;
3
+ export declare const build: (api: PluginAPI, config: IBuildConfig, modernConfig: NormalizedConfig) => Promise<void>;
@@ -1,7 +1,8 @@
1
+ import type { PluginAPI } from '@modern-js/core';
1
2
  import type { IBuildConfig, IPackageModeValue, ITaskMapper } from '../../types';
2
3
  import type { LoggerText } from './logger';
3
- export declare const getCodeInitMapper: (_: IBuildConfig) => IPackageModeValue[];
4
- export declare const getCodeMapper: ({
4
+ export declare const getCodeInitMapper: (api: PluginAPI, _: IBuildConfig) => IPackageModeValue[];
5
+ export declare const getCodeMapper: (api: PluginAPI, {
5
6
  logger,
6
7
  taskPath,
7
8
  config,
@@ -18,7 +19,7 @@ export declare const getCodeMapper: ({
18
19
  taskPath: string;
19
20
  params: string[];
20
21
  }[];
21
- export declare const getDtsMapper: (config: IBuildConfig, logger: LoggerText) => {
22
+ export declare const getDtsMapper: (api: PluginAPI, config: IBuildConfig, logger: LoggerText) => {
22
23
  logger: LoggerText;
23
24
  taskPath: string;
24
25
  params: string[];
@@ -1,8 +1,9 @@
1
+ import type { PluginAPI } from '@modern-js/core';
1
2
  export interface IDevConfig {
2
3
  appDirectory: string;
3
4
  isTsProject: boolean;
4
5
  }
5
6
  export declare type DevTaskType = 'storybook' | 'docsite' | 'unknow';
6
- export declare const showMenu: (config: IDevConfig) => Promise<void>;
7
- export declare const devStorybook: (config: IDevConfig) => Promise<void>;
8
- export declare const runSubCmd: (subCmd: string, config: IDevConfig) => Promise<void>;
7
+ export declare const showMenu: (api: PluginAPI, config: IDevConfig) => Promise<void>;
8
+ export declare const devStorybook: (api: PluginAPI, config: IDevConfig) => Promise<void>;
9
+ export declare const runSubCmd: (api: PluginAPI, subCmd: string, config: IDevConfig) => Promise<void>;
@@ -0,0 +1,46 @@
1
+ import { NormalizedConfig } from '@modern-js/core';
2
+ import { LessOption, SassOptions } from '@modern-js/style-compiler';
3
+ export interface PlatformBuildOption {
4
+ isTsProject: boolean;
5
+ }
6
+ export declare const platformBuild: import("@modern-js/plugin").ParallelWorkflow<PlatformBuildOption, {
7
+ name: string;
8
+ title: string;
9
+ taskPath: string;
10
+ params: string[];
11
+ }>;
12
+ export declare const moduleLessConfig: import("@modern-js/plugin").AsyncPipeline<{
13
+ modernConfig: NormalizedConfig;
14
+ }, LessOption | undefined>;
15
+ export declare const moduleSassConfig: import("@modern-js/plugin").AsyncPipeline<{
16
+ modernConfig: NormalizedConfig;
17
+ }, SassOptions<"sync"> | undefined>;
18
+ export declare const moduleTailwindConfig: import("@modern-js/plugin").AsyncPipeline<{
19
+ modernConfig: NormalizedConfig;
20
+ }, any>;
21
+ export declare const buildHooks: {
22
+ platformBuild: import("@modern-js/plugin").ParallelWorkflow<PlatformBuildOption, {
23
+ name: string;
24
+ title: string;
25
+ taskPath: string;
26
+ params: string[];
27
+ }>;
28
+ moduleLessConfig: import("@modern-js/plugin").AsyncPipeline<{
29
+ modernConfig: NormalizedConfig;
30
+ }, LessOption | undefined>;
31
+ moduleSassConfig: import("@modern-js/plugin").AsyncPipeline<{
32
+ modernConfig: NormalizedConfig;
33
+ }, SassOptions<"sync"> | undefined>;
34
+ moduleTailwindConfig: import("@modern-js/plugin").AsyncPipeline<{
35
+ modernConfig: NormalizedConfig;
36
+ }, any>;
37
+ };
38
+ export declare const lifecycle: () => void;
39
+ declare module '@modern-js/core' {
40
+ interface Hooks {
41
+ platformBuild: typeof platformBuild;
42
+ moduleLessConfig: typeof moduleLessConfig;
43
+ moduleSassConfig: typeof moduleSassConfig;
44
+ moduleTailwindConfig: typeof moduleTailwindConfig;
45
+ }
46
+ }
@@ -0,0 +1,18 @@
1
+ export declare const moduleToolsMenu: import("@modern-js/plugin").ParallelWorkflow<undefined, {
2
+ name: string;
3
+ value: string;
4
+ runTask: (p: any) => void | Promise<void>;
5
+ }>;
6
+ export declare const devHooks: {
7
+ moduleToolsMenu: import("@modern-js/plugin").ParallelWorkflow<undefined, {
8
+ name: string;
9
+ value: string;
10
+ runTask: (p: any) => void | Promise<void>;
11
+ }>;
12
+ };
13
+ export declare const lifecycle: () => void;
14
+ declare module '@modern-js/core' {
15
+ interface Hooks {
16
+ moduleToolsMenu: typeof moduleToolsMenu;
17
+ }
18
+ }
@@ -0,0 +1,26 @@
1
+ import { lifecycle as buildLifeCycle } from './build';
2
+ import { lifecycle as devLifeCycle } from './dev';
3
+ export { buildLifeCycle, devLifeCycle };
4
+ export declare const lifecycle: () => void;
5
+ export declare const hooks: {
6
+ moduleToolsMenu: import("@modern-js/plugin").ParallelWorkflow<undefined, {
7
+ name: string;
8
+ value: string;
9
+ runTask: (p: any) => void | Promise<void>;
10
+ }>;
11
+ platformBuild: import("@modern-js/plugin").ParallelWorkflow<import("./build").PlatformBuildOption, {
12
+ name: string;
13
+ title: string;
14
+ taskPath: string;
15
+ params: string[];
16
+ }>;
17
+ moduleLessConfig: import("@modern-js/plugin").AsyncPipeline<{
18
+ modernConfig: import("@modern-js/core").NormalizedConfig;
19
+ }, import("@modern-js/style-compiler").LessOption | undefined>;
20
+ moduleSassConfig: import("@modern-js/plugin").AsyncPipeline<{
21
+ modernConfig: import("@modern-js/core").NormalizedConfig;
22
+ }, import("@modern-js/style-compiler").SassOptions<"sync"> | undefined>;
23
+ moduleTailwindConfig: import("@modern-js/plugin").AsyncPipeline<{
24
+ modernConfig: import("@modern-js/core").NormalizedConfig;
25
+ }, any>;
26
+ };
@@ -1,22 +1,6 @@
1
- export declare const defineConfig: (config: import("@modern-js/core/src/config").ConfigParam) => import("@modern-js/core/src/config").ConfigParam;
1
+ import type { CliPlugin } from '@modern-js/core';
2
+ export { defineConfig } from '@modern-js/core';
2
3
 
3
- declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
4
- config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
5
- resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
6
- resolved: import("@modern-js/core").NormalizedConfig;
7
- }>;
8
- validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
9
- prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
10
- commands: import("@modern-js/core").AsyncWorkflow<{
11
- program: import("commander").Command;
12
- }, void>;
13
- watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
14
- fileChange: import("@modern-js/core").AsyncWorkflow<{
15
- filename: string;
16
- eventType: "add" | "unlink" | "change";
17
- }, void>;
18
- beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
19
- beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
20
- } & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
4
+ declare const _default: () => CliPlugin;
21
5
 
22
6
  export default _default;
@@ -20,4 +20,5 @@ export declare const generatorTsConfig: (projectTsconfig: ITsconfig, {
20
20
  distDir: string;
21
21
  sourceDir?: string | undefined;
22
22
  }) => string;
23
- export declare const resolveAlias: (modernConfig: NormalizedConfig, config: IGeneratorConfig, watchFilenames?: string[]) => void;
23
+ export declare const resolveAlias: (modernConfig: NormalizedConfig, config: IGeneratorConfig, watchFilenames?: string[]) => void;
24
+ export declare const getTscBinPath: (appDirectory: string) => string;
@@ -1,8 +1,7 @@
1
- import { TransformOptions } from '@babel/core';
2
1
  import { NormalizedConfig } from '@modern-js/core';
3
2
  import { IPackageModeValue } from '../types';
4
3
  export declare const getFinalAlias: any;
5
4
  export declare const resolveBabelConfig: (appDirectory: string, modernConfig: NormalizedConfig, option: Pick<IPackageModeValue, 'syntax' | 'type'> & {
6
5
  sourceAbsDir: string;
7
6
  tsconfigPath: string;
8
- }) => TransformOptions;
7
+ }) => import("@modern-js/core").TransformOptions;
package/jest.config.js CHANGED
@@ -1,10 +1,7 @@
1
1
  const sharedConfig = require('@scripts/jest-config');
2
2
 
3
- console.info(sharedConfig.coveragePathIgnorePatterns);
4
-
5
3
  /** @type {import('@jest/types').Config.InitialOptions} */
6
4
  module.exports = {
7
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
8
5
  ...sharedConfig,
9
6
  rootDir: __dirname,
10
7
  };
package/lib/types.d.ts CHANGED
@@ -55,6 +55,98 @@ declare module '*.svg' {
55
55
  export default src;
56
56
  }
57
57
 
58
+ declare module '*.bmp?inline' {
59
+ const src: string;
60
+ export default src;
61
+ }
62
+
63
+ declare module '*.gif?inline' {
64
+ const src: string;
65
+ export default src;
66
+ }
67
+
68
+ declare module '*.jpg?inline' {
69
+ const src: string;
70
+ export default src;
71
+ }
72
+
73
+ declare module '*.jpeg?inline' {
74
+ const src: string;
75
+ export default src;
76
+ }
77
+
78
+ declare module '*.png?inline' {
79
+ const src: string;
80
+ export default src;
81
+ }
82
+
83
+ declare module '*.ico?inline' {
84
+ const src: string;
85
+ export default src;
86
+ }
87
+
88
+ declare module '*.webp?inline' {
89
+ const src: string;
90
+ export default src;
91
+ }
92
+
93
+ declare module '*.svg?inline' {
94
+ import * as React from 'react';
95
+
96
+ export const ReactComponent: React.FunctionComponent<
97
+ React.SVGProps<SVGSVGElement>
98
+ >;
99
+
100
+ const src: string;
101
+ export default src;
102
+ }
103
+
104
+ declare module '*.bmp?url' {
105
+ const src: string;
106
+ export default src;
107
+ }
108
+
109
+ declare module '*.gif?url' {
110
+ const src: string;
111
+ export default src;
112
+ }
113
+
114
+ declare module '*.jpg?url' {
115
+ const src: string;
116
+ export default src;
117
+ }
118
+
119
+ declare module '*.jpeg?url' {
120
+ const src: string;
121
+ export default src;
122
+ }
123
+
124
+ declare module '*.png?url' {
125
+ const src: string;
126
+ export default src;
127
+ }
128
+
129
+ declare module '*.ico?url' {
130
+ const src: string;
131
+ export default src;
132
+ }
133
+
134
+ declare module '*.webp?url' {
135
+ const src: string;
136
+ export default src;
137
+ }
138
+
139
+ declare module '*.svg?url' {
140
+ import * as React from 'react';
141
+
142
+ export const ReactComponent: React.FunctionComponent<
143
+ React.SVGProps<SVGSVGElement>
144
+ >;
145
+
146
+ const src: string;
147
+ export default src;
148
+ }
149
+
58
150
  declare module '*.css' {
59
151
  const classes: { readonly [key: string]: string };
60
152
  export default classes;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.1",
14
+ "version": "1.4.4",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js"
17
17
  },
@@ -40,6 +40,9 @@
40
40
  },
41
41
  "typesVersions": {
42
42
  "*": {
43
+ "types": [
44
+ "./lib/types.d.ts"
45
+ ],
43
46
  "type": [
44
47
  "./lib/types.d.ts"
45
48
  ]
@@ -50,21 +53,21 @@
50
53
  "@babel/parser": "^7.15.2",
51
54
  "@babel/runtime": "^7",
52
55
  "@babel/traverse": "^7.15.0",
53
- "@babel/types": "^7.15.0",
54
- "@modern-js/babel-compiler": "^1.2.1",
56
+ "@babel/types": "^7.17.0",
57
+ "@modern-js/babel-compiler": "^1.2.2",
55
58
  "@modern-js/babel-preset-module": "^1.3.1",
56
- "@modern-js/css-config": "^1.2.2",
59
+ "@modern-js/core": "^1.6.1",
60
+ "@modern-js/css-config": "^1.2.3",
57
61
  "@modern-js/i18n-cli-language-detector": "^1.2.1",
58
- "@modern-js/module-tools-hooks": "^1.2.2",
59
- "@modern-js/new-action": "^1.3.2",
60
- "@modern-js/plugin-analyze": "^1.3.3",
61
- "@modern-js/plugin-changeset": "^1.2.2",
62
- "@modern-js/plugin-fast-refresh": "^1.2.1",
62
+ "@modern-js/new-action": "^1.3.3",
63
+ "@modern-js/plugin": "^1.3.2",
64
+ "@modern-js/plugin-analyze": "^1.3.5",
65
+ "@modern-js/plugin-changeset": "^1.2.4",
66
+ "@modern-js/plugin-fast-refresh": "^1.2.3",
63
67
  "@modern-js/plugin-i18n": "^1.2.1",
64
68
  "@modern-js/style-compiler": "^1.2.2",
65
- "@modern-js/utils": "^1.3.2",
69
+ "@modern-js/utils": "^1.3.7",
66
70
  "chalk": "^4.1.2",
67
- "chokidar": "^3.5.2",
68
71
  "dotenv": "^10.0.0",
69
72
  "execa": "^5.1.1",
70
73
  "fast-glob": "^3.2.5",
@@ -76,16 +79,13 @@
76
79
  "normalize-path": "^3.0.0",
77
80
  "p-map": "^4",
78
81
  "process.argv": "^0.6.0",
79
- "signale": "^1.4.0",
80
82
  "tsconfig-paths": "^3.10.1"
81
83
  },
82
- "peerDependencies": {
83
- "@modern-js/core": "^1.4.3"
84
- },
85
84
  "devDependencies": {
86
- "@modern-js/core": "^1.4.3",
87
85
  "@babel/preset-typescript": "^7.15.0",
88
86
  "@modern-js/babel-chain": "^1.2.1",
87
+ "@scripts/build": "0.0.0",
88
+ "@scripts/jest-config": "0.0.0",
89
89
  "@types/babel__core": "^7.1.15",
90
90
  "@types/babel__generator": "^7.6.3",
91
91
  "@types/babel__traverse": "^7.14.2",
@@ -95,12 +95,11 @@
95
95
  "@types/lodash.merge": "^4.6.6",
96
96
  "@types/node": "^14",
97
97
  "@types/normalize-path": "^3.0.0",
98
- "@types/signale": "^1.4.2",
98
+ "@types/react": "^17",
99
+ "@types/react-dom": "^17",
99
100
  "commander": "^8.1.0",
100
- "typescript": "^4",
101
- "@scripts/build": "0.0.0",
102
101
  "jest": "^27",
103
- "@scripts/jest-config": "0.0.0"
102
+ "typescript": "^4"
104
103
  },
105
104
  "sideEffects": false,
106
105
  "modernConfig": {
@@ -1,3 +1,4 @@
1
+ import { manager } from '@modern-js/core';
1
2
  import { program } from 'commander';
2
3
  import { devCli } from '../src/cli/dev';
3
4
 
@@ -11,15 +12,48 @@ describe('dev cli subCmd', () => {
11
12
  dev: mockCommandDev,
12
13
  }));
13
14
  });
14
- it('should be storybook with "dev storybook"', () => {
15
- devCli(program);
16
- program.parse(['', '', 'dev', 'storybook']);
17
- expect(mockCommandDev.mock.calls[0][1]).toBe('storybook');
15
+ it('should be storybook with "dev storybook"', async () => {
16
+ const mockAPI = {
17
+ useAppContext: jest.fn((): any => ({
18
+ existSrc: false,
19
+ distDirectory: '',
20
+ })),
21
+ useResolvedConfigContext: jest.fn(),
22
+ useHookRunners: (): any => ({}),
23
+ };
24
+ const cloned = manager.clone(mockAPI);
25
+ cloned.usePlugin({
26
+ setup(api) {
27
+ devCli(program, api);
28
+ program.parse(['', '', 'dev', 'storybook']);
29
+ expect(mockCommandDev.mock.calls[0][2]).toBe('storybook');
30
+ },
31
+ });
32
+ await cloned.init();
18
33
  });
19
34
 
20
- it('should be undefined with "dev"', () => {
21
- devCli(program);
22
- program.parse(['', '', 'dev']);
23
- expect(mockCommandDev.mock.calls[0][1]).toBe(undefined);
35
+ it('should be undefined with "dev"', async () => {
36
+ const mockBeforeBuild = jest.fn();
37
+ const mockAfterBuild = jest.fn();
38
+ const mockAPI = {
39
+ useAppContext: jest.fn((): any => ({
40
+ existSrc: false,
41
+ distDirectory: '',
42
+ })),
43
+ useResolvedConfigContext: jest.fn(),
44
+ useHookRunners: (): any => ({
45
+ afterBuild: mockAfterBuild,
46
+ beforeBuild: mockBeforeBuild,
47
+ }),
48
+ };
49
+ const cloned = manager.clone(mockAPI);
50
+ cloned.usePlugin({
51
+ setup(api) {
52
+ devCli(program, api);
53
+ program.parse(['', '', 'dev']);
54
+ expect(mockCommandDev.mock.calls[0][2]).toBe(undefined);
55
+ },
56
+ });
57
+ await cloned.init();
24
58
  });
25
59
  });