@modern-js/utils 3.0.0-alpha.1 → 3.0.0-alpha.2

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 (88) hide show
  1. package/dist/cjs/cli/common.js +12 -2
  2. package/dist/cjs/cli/index.js +32 -39
  3. package/dist/cjs/cli/is/project.js +7 -12
  4. package/dist/cjs/cli/require.js +32 -30
  5. package/dist/cjs/compiled.js +90 -89
  6. package/dist/cjs/import.js +23 -28
  7. package/dist/compiled/commander/index.mjs +2 -0
  8. package/dist/compiled/js-yaml/index.js +102 -99
  9. package/dist/compiled/js-yaml/index.mjs +2167 -0
  10. package/dist/compiled/js-yaml/index.mjs.LICENSE.txt +1 -0
  11. package/dist/compiled/js-yaml/package.json +1 -1
  12. package/dist/compiled/lodash/index.mjs +1 -0
  13. package/dist/compiled/nanoid/index.js +4 -4
  14. package/dist/compiled/nanoid/index.mjs +69 -0
  15. package/dist/compiled/nanoid/package.json +1 -1
  16. package/dist/compiled/tsconfig-paths/index.mjs +2 -0
  17. package/dist/esm/cli/alias.mjs +2 -2
  18. package/dist/esm/cli/applyOptionsChain.mjs +2 -2
  19. package/dist/esm/cli/commands.mjs +1 -1
  20. package/dist/esm/cli/common.mjs +2 -4
  21. package/dist/esm/cli/constants.mjs +1 -1
  22. package/dist/esm/cli/fs.mjs +1 -1
  23. package/dist/esm/cli/get/config.mjs +1 -1
  24. package/dist/esm/cli/get/data.mjs +3 -3
  25. package/dist/esm/cli/get/index.mjs +4 -4
  26. package/dist/esm/cli/index.mjs +21 -22
  27. package/dist/esm/cli/is/config.mjs +2 -2
  28. package/dist/esm/cli/is/index.mjs +4 -4
  29. package/dist/esm/cli/is/project.mjs +10 -39
  30. package/dist/esm/cli/monorepo.mjs +1 -1
  31. package/dist/esm/cli/package.mjs +1 -1
  32. package/dist/esm/cli/path.mjs +1 -1
  33. package/dist/esm/cli/port.mjs +2 -2
  34. package/dist/esm/cli/prettyInstructions.mjs +3 -3
  35. package/dist/esm/cli/require.mjs +43 -37
  36. package/dist/esm/cli/route.mjs +1 -1
  37. package/dist/esm/cli/watch.mjs +1 -1
  38. package/dist/esm/compiled.mjs +46 -111
  39. package/dist/esm/import.mjs +3 -19
  40. package/dist/esm/index.mjs +3 -3
  41. package/dist/esm/universal/index.mjs +1 -1
  42. package/dist/esm-node/cli/alias.mjs +2 -0
  43. package/dist/esm-node/cli/applyOptionsChain.mjs +2 -0
  44. package/dist/esm-node/cli/commands.mjs +2 -0
  45. package/dist/esm-node/cli/common.mjs +4 -4
  46. package/dist/esm-node/cli/config.mjs +2 -0
  47. package/dist/esm-node/cli/constants.mjs +2 -0
  48. package/dist/esm-node/cli/ensure.mjs +2 -0
  49. package/dist/esm-node/cli/fs.mjs +2 -0
  50. package/dist/esm-node/cli/get/config.mjs +2 -0
  51. package/dist/esm-node/cli/get/data.mjs +2 -0
  52. package/dist/esm-node/cli/get/index.mjs +2 -0
  53. package/dist/esm-node/cli/index.mjs +2 -1
  54. package/dist/esm-node/cli/is/config.mjs +2 -0
  55. package/dist/esm-node/cli/is/env.mjs +2 -0
  56. package/dist/esm-node/cli/is/index.mjs +2 -0
  57. package/dist/esm-node/cli/is/project.mjs +8 -35
  58. package/dist/esm-node/cli/is/type.mjs +2 -0
  59. package/dist/esm-node/cli/logger.mjs +2 -0
  60. package/dist/esm-node/cli/monorepo.mjs +2 -0
  61. package/dist/esm-node/cli/package.mjs +2 -0
  62. package/dist/esm-node/cli/path.mjs +2 -0
  63. package/dist/esm-node/cli/port.mjs +2 -0
  64. package/dist/esm-node/cli/prettyInstructions.mjs +2 -0
  65. package/dist/esm-node/cli/require.mjs +44 -36
  66. package/dist/esm-node/cli/route.mjs +2 -0
  67. package/dist/esm-node/cli/runtimeExports.mjs +2 -0
  68. package/dist/esm-node/cli/version.mjs +2 -0
  69. package/dist/esm-node/cli/watch.mjs +2 -0
  70. package/dist/esm-node/compiled.mjs +39 -113
  71. package/dist/esm-node/import.mjs +5 -19
  72. package/dist/esm-node/index.mjs +2 -0
  73. package/dist/esm-node/universal/constants.mjs +2 -0
  74. package/dist/esm-node/universal/index.mjs +2 -0
  75. package/dist/esm-node/universal/path.mjs +2 -0
  76. package/dist/esm-node/universal/pluginDagSort.mjs +2 -0
  77. package/dist/types/cli/common.d.ts +2 -1
  78. package/dist/types/cli/index.d.ts +0 -1
  79. package/dist/types/cli/require.d.ts +1 -13
  80. package/dist/types/compiled.d.ts +2 -1
  81. package/dist/types/import.d.ts +2 -2
  82. package/package.json +36 -56
  83. package/rslib.config.mts +49 -26
  84. package/rstest.config.ts +8 -0
  85. package/dist/cjs/cli/babel.js +0 -113
  86. package/dist/esm/cli/babel.mjs +0 -76
  87. package/dist/esm-node/cli/babel.mjs +0 -76
  88. package/dist/types/cli/babel.d.ts +0 -3
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- applyUserBabelConfig: ()=>applyUserBabelConfig,
28
- getBabelUtils: ()=>getBabelUtils
29
- });
30
- const external_path_namespaceObject = require("path");
31
- const external_applyOptionsChain_js_namespaceObject = require("./applyOptionsChain.js");
32
- const external_ensure_js_namespaceObject = require("./ensure.js");
33
- const external_path_js_namespaceObject = require("./path.js");
34
- const formatPath = (originPath)=>{
35
- if ((0, external_path_namespaceObject.isAbsolute)(originPath)) return originPath.split(external_path_namespaceObject.sep).join('/');
36
- return originPath;
37
- };
38
- const getPluginItemName = (item)=>{
39
- if ('string' == typeof item) return formatPath(item);
40
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
41
- return null;
42
- };
43
- const addPlugins = (plugins, config)=>{
44
- if (config.plugins) config.plugins.push(...plugins);
45
- else config.plugins = plugins;
46
- };
47
- const addPresets = (presets, config)=>{
48
- if (config.presets) config.presets.push(...presets);
49
- else config.presets = presets;
50
- };
51
- const removePlugins = (plugins, config)=>{
52
- if (!config.plugins) return;
53
- const removeList = (0, external_ensure_js_namespaceObject.ensureArray)(plugins);
54
- config.plugins = config.plugins.filter((item)=>{
55
- const name = getPluginItemName(item);
56
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
57
- return true;
58
- });
59
- };
60
- const removePresets = (presets, config)=>{
61
- if (!config.presets) return;
62
- const removeList = (0, external_ensure_js_namespaceObject.ensureArray)(presets);
63
- config.presets = config.presets.filter((item)=>{
64
- const name = getPluginItemName(item);
65
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
66
- return true;
67
- });
68
- };
69
- const modifyPresetOptions = (presetName, options, presets = [])=>{
70
- presets.forEach((preset, index)=>{
71
- if (Array.isArray(preset)) {
72
- if ('string' == typeof preset[0] && (0, external_path_js_namespaceObject.normalizeToPosixPath)(preset[0]).includes(presetName)) preset[1] = {
73
- ...preset[1] || {},
74
- ...options
75
- };
76
- } else if ('string' == typeof preset && (0, external_path_js_namespaceObject.normalizeToPosixPath)(preset).includes(presetName)) presets[index] = [
77
- preset,
78
- options
79
- ];
80
- });
81
- };
82
- const getBabelUtils = (config)=>{
83
- const noop = ()=>{};
84
- return {
85
- addPlugins: (plugins)=>addPlugins(plugins, config),
86
- addPresets: (presets)=>addPresets(presets, config),
87
- removePlugins: (plugins)=>removePlugins(plugins, config),
88
- removePresets: (presets)=>removePresets(presets, config),
89
- addIncludes: noop,
90
- addExcludes: noop,
91
- modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
92
- modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
93
- };
94
- };
95
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
96
- if (userBabelConfig) {
97
- const babelUtils = {
98
- ...getBabelUtils(defaultOptions),
99
- ...extraBabelUtils
100
- };
101
- return (0, external_applyOptionsChain_js_namespaceObject.applyOptionsChain)(defaultOptions, userBabelConfig || {}, babelUtils);
102
- }
103
- return defaultOptions;
104
- };
105
- exports.applyUserBabelConfig = __webpack_exports__.applyUserBabelConfig;
106
- exports.getBabelUtils = __webpack_exports__.getBabelUtils;
107
- for(var __rspack_i in __webpack_exports__)if (-1 === [
108
- "applyUserBabelConfig",
109
- "getBabelUtils"
110
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
111
- Object.defineProperty(exports, '__esModule', {
112
- value: true
113
- });
@@ -1,76 +0,0 @@
1
- import { isAbsolute, sep } from "path";
2
- import { applyOptionsChain } from "./applyOptionsChain";
3
- import { ensureArray } from "./ensure";
4
- import { normalizeToPosixPath } from "./path";
5
- const formatPath = (originPath)=>{
6
- if (isAbsolute(originPath)) return originPath.split(sep).join('/');
7
- return originPath;
8
- };
9
- const getPluginItemName = (item)=>{
10
- if ('string' == typeof item) return formatPath(item);
11
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
12
- return null;
13
- };
14
- const addPlugins = (plugins, config)=>{
15
- if (config.plugins) config.plugins.push(...plugins);
16
- else config.plugins = plugins;
17
- };
18
- const addPresets = (presets, config)=>{
19
- if (config.presets) config.presets.push(...presets);
20
- else config.presets = presets;
21
- };
22
- const removePlugins = (plugins, config)=>{
23
- if (!config.plugins) return;
24
- const removeList = ensureArray(plugins);
25
- config.plugins = config.plugins.filter((item)=>{
26
- const name = getPluginItemName(item);
27
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
28
- return true;
29
- });
30
- };
31
- const removePresets = (presets, config)=>{
32
- if (!config.presets) return;
33
- const removeList = ensureArray(presets);
34
- config.presets = config.presets.filter((item)=>{
35
- const name = getPluginItemName(item);
36
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
37
- return true;
38
- });
39
- };
40
- const modifyPresetOptions = (presetName, options, presets = [])=>{
41
- presets.forEach((preset, index)=>{
42
- if (Array.isArray(preset)) {
43
- if ('string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName)) preset[1] = {
44
- ...preset[1] || {},
45
- ...options
46
- };
47
- } else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) presets[index] = [
48
- preset,
49
- options
50
- ];
51
- });
52
- };
53
- const getBabelUtils = (config)=>{
54
- const noop = ()=>{};
55
- return {
56
- addPlugins: (plugins)=>addPlugins(plugins, config),
57
- addPresets: (presets)=>addPresets(presets, config),
58
- removePlugins: (plugins)=>removePlugins(plugins, config),
59
- removePresets: (presets)=>removePresets(presets, config),
60
- addIncludes: noop,
61
- addExcludes: noop,
62
- modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
63
- modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
64
- };
65
- };
66
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
67
- if (userBabelConfig) {
68
- const babelUtils = {
69
- ...getBabelUtils(defaultOptions),
70
- ...extraBabelUtils
71
- };
72
- return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
73
- }
74
- return defaultOptions;
75
- };
76
- export { applyUserBabelConfig, getBabelUtils };
@@ -1,76 +0,0 @@
1
- import { isAbsolute, sep } from "path";
2
- import { applyOptionsChain } from "./applyOptionsChain.mjs";
3
- import { ensureArray } from "./ensure.mjs";
4
- import { normalizeToPosixPath } from "./path.mjs";
5
- const formatPath = (originPath)=>{
6
- if (isAbsolute(originPath)) return originPath.split(sep).join('/');
7
- return originPath;
8
- };
9
- const getPluginItemName = (item)=>{
10
- if ('string' == typeof item) return formatPath(item);
11
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
12
- return null;
13
- };
14
- const addPlugins = (plugins, config)=>{
15
- if (config.plugins) config.plugins.push(...plugins);
16
- else config.plugins = plugins;
17
- };
18
- const addPresets = (presets, config)=>{
19
- if (config.presets) config.presets.push(...presets);
20
- else config.presets = presets;
21
- };
22
- const removePlugins = (plugins, config)=>{
23
- if (!config.plugins) return;
24
- const removeList = ensureArray(plugins);
25
- config.plugins = config.plugins.filter((item)=>{
26
- const name = getPluginItemName(item);
27
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
28
- return true;
29
- });
30
- };
31
- const removePresets = (presets, config)=>{
32
- if (!config.presets) return;
33
- const removeList = ensureArray(presets);
34
- config.presets = config.presets.filter((item)=>{
35
- const name = getPluginItemName(item);
36
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
37
- return true;
38
- });
39
- };
40
- const modifyPresetOptions = (presetName, options, presets = [])=>{
41
- presets.forEach((preset, index)=>{
42
- if (Array.isArray(preset)) {
43
- if ('string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName)) preset[1] = {
44
- ...preset[1] || {},
45
- ...options
46
- };
47
- } else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) presets[index] = [
48
- preset,
49
- options
50
- ];
51
- });
52
- };
53
- const getBabelUtils = (config)=>{
54
- const noop = ()=>{};
55
- return {
56
- addPlugins: (plugins)=>addPlugins(plugins, config),
57
- addPresets: (presets)=>addPresets(presets, config),
58
- removePlugins: (plugins)=>removePlugins(plugins, config),
59
- removePresets: (presets)=>removePresets(presets, config),
60
- addIncludes: noop,
61
- addExcludes: noop,
62
- modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
63
- modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
64
- };
65
- };
66
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
67
- if (userBabelConfig) {
68
- const babelUtils = {
69
- ...getBabelUtils(defaultOptions),
70
- ...extraBabelUtils
71
- };
72
- return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
73
- }
74
- return defaultOptions;
75
- };
76
- export { applyUserBabelConfig, getBabelUtils };
@@ -1,3 +0,0 @@
1
- import type { BabelConfig, BabelConfigUtils, BabelTransformOptions } from '@modern-js/types';
2
- export declare const getBabelUtils: (config: BabelTransformOptions) => BabelConfigUtils;
3
- export declare const applyUserBabelConfig: (defaultOptions: BabelTransformOptions, userBabelConfig?: BabelConfig | BabelConfig[], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelTransformOptions;