@nlabs/lex 1.30.0 → 1.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlabs/lex",
3
- "version": "1.30.0",
3
+ "version": "1.32.1",
4
4
  "description": "Lex",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -26,14 +26,14 @@
26
26
  "url": "https://github.com/nitrogenlabs/lex/issues"
27
27
  },
28
28
  "engines": {
29
- "node": ">=14"
29
+ "node": ">=16"
30
30
  },
31
31
  "browserslist": [
32
32
  "last 5 version",
33
33
  "ie 11"
34
34
  ],
35
35
  "scripts": {
36
- "build": "NODE_ENV=production && rm -rf dist && esbuild src/**/**.ts* src/**.ts* --platform=node --outdir=./dist --target=node14 --format=cjs",
36
+ "build": "NODE_ENV=production && rm -rf dist && esbuild src/**/**.ts* src/**.ts* --platform=node --outdir=./dist --sourcemap=inline --target=node14 --format=cjs",
37
37
  "clean": "rm -rf dist node_modules package-lock.json *.log coverage",
38
38
  "compile": "tsc -p tsconfig.build.json",
39
39
  "env": "LEX_CONFIG='{\"useTypescript\":true}'",
@@ -45,104 +45,106 @@
45
45
  "watch": "NODE_ENV=development rm -rf dist && yarn compile -w"
46
46
  },
47
47
  "dependencies": {
48
- "@hot-loader/react-dom": "17.0.1",
48
+ "@luckycatfactory/esbuild-graphql-loader": "^3.7.0",
49
49
  "@nlabs/gothamjs": "^0.8.2",
50
50
  "@nlabs/webpack-plugin-static-site": "^0.1.1",
51
- "acorn": "^8.5.0",
51
+ "acorn": "^8.7.0",
52
52
  "acorn-dynamic-import": "^4.0.0",
53
53
  "assert": "^2.0.0",
54
- "boxen": "^5.1.2",
55
- "caniuse-lite": "1.0.30001258",
54
+ "boxen": "5.1.2",
55
+ "caniuse-lite": "1.0.30001309",
56
56
  "chalk": "^4.1.2",
57
57
  "commander": "^8.2.0",
58
- "compare-versions": "^3.6.0",
59
- "compression-webpack-plugin": "^9.0.0",
58
+ "compare-versions": "^4.1.3",
59
+ "compression-webpack-plugin": "^9.2.0",
60
60
  "config-webpack-plugin": "^1.1.0",
61
- "copy-webpack-plugin": "^9.0.1",
62
- "core-js": "^3.18.0",
61
+ "copy-webpack-plugin": "^10.2.4",
62
+ "core-js": "^3.21.1",
63
63
  "crypto-browserify": "^3.12.0",
64
- "css-loader": "^6.3.0",
65
- "cssnano": "^5.0.8",
66
- "dotenv-webpack": "^7.0.3",
64
+ "css-loader": "^6.7.1",
65
+ "cssnano": "^5.1.5",
66
+ "dotenv-webpack": "^7.1.0",
67
67
  "download-npm-package": "^3.1.12",
68
+ "esbuild": "^0.14.29",
68
69
  "esbuild-jest": "^0.5.0",
69
- "esbuild-loader": "^2.15.1",
70
+ "esbuild-loader": "^2.18.0",
70
71
  "execa": "5",
71
- "exports-loader": "^3.0.0",
72
+ "exports-loader": "^3.1.0",
72
73
  "favicons-webpack-plugin": "^5.0.2",
73
74
  "file-loader": "^6.2.0",
74
75
  "find-file-up": "^2.0.1",
75
- "fs-extra": "^10.0.0",
76
- "glob": "^7.1.6",
77
- "graphql-tag": "^2.12.5",
78
- "html-loader": "^2.1.2",
79
- "html-webpack-plugin": "^5.3.2",
76
+ "fs-extra": "^10.0.1",
77
+ "glob": "^7.2.0",
78
+ "graphql": "^16.3.0",
79
+ "graphql-tag": "^2.12.6",
80
+ "html-loader": "^3.1.0",
81
+ "html-webpack-plugin": "^5.5.0",
80
82
  "https-browserify": "^1.0.0",
81
- "imports-loader": "^3.0.0",
82
- "jest": "^27.2.1",
83
- "jest-cli": "^27.2.1",
83
+ "imports-loader": "^3.1.1",
84
+ "jest": "^27.5.1",
85
+ "jest-cli": "^27.5.1",
84
86
  "jest-transform-graphql": "^2.1.0",
85
87
  "json-d-ts": "^1.0.1",
86
88
  "latest-version": "5.1.0",
87
89
  "lodash": "^4.17.21",
88
- "luxon": "^2.0.2",
90
+ "luxon": "^2.3.1",
89
91
  "net": "^1.0.2",
90
- "npm-check-updates": "^11.8.5",
92
+ "npm-check-updates": "^12.5.4",
91
93
  "ora": "5.4.1",
92
94
  "os-browserify": "^0.3.0",
93
95
  "path-browserify": "^1.0.1",
94
96
  "postcss-browser-reporter": "^0.6.0",
95
- "postcss-cli": "^8.3.1",
96
- "postcss-custom-properties": "^12.0.0",
97
+ "postcss-cli": "^9.1.0",
98
+ "postcss-custom-properties": "^12.1.5",
97
99
  "postcss-flexbugs-fixes": "^5.0.2",
98
100
  "postcss-for": "^2.1.1",
99
101
  "postcss-hash": "^3.0.0",
100
- "postcss-import": "14.0.2",
101
- "postcss-loader": "^6.1.1",
102
- "postcss-nesting": "^8.0.1",
102
+ "postcss-import": "14.1.0",
103
+ "postcss-loader": "^6.2.1",
104
+ "postcss-nesting": "^10.1.3",
103
105
  "postcss-percentage": "^0.0.0",
104
- "postcss-preset-env": "^6.7.0",
106
+ "postcss-preset-env": "^7.4.3",
105
107
  "postcss-simple-vars": "^6.0.3",
106
- "postcss-svgo": "5.0.2",
108
+ "postcss-svgo": "5.1.0",
107
109
  "postcss-url": "10.1.3",
108
110
  "process": "^0.11.10",
109
- "react": "^17.0.2",
110
- "react-dom": "^17.0.2",
111
+ "react": "^18.0.0",
112
+ "react-dom": "^18.0.0",
111
113
  "regenerator-runtime": "^0.13.9",
112
- "resolve": "^1.20.0",
114
+ "resolve": "^1.22.0",
113
115
  "rimraf": "^3.0.2",
114
116
  "semver": "^7.3.5",
115
- "source-map-loader": "^3.0.0",
116
- "source-map-support": "^0.5.20",
117
+ "source-map-loader": "^3.0.1",
118
+ "source-map-support": "^0.5.21",
117
119
  "speed-measure-webpack-plugin": "^1.5.0",
118
120
  "static-site-generator-webpack-plugin": "^3.4.2",
119
121
  "stream-browserify": "^3.0.0",
120
122
  "stream-http": "^3.2.0",
121
- "style-loader": "^3.2.1",
122
- "svg-spritemap-webpack-plugin": "^4.3.2",
123
- "svgo": "2.6.1",
123
+ "style-loader": "^3.3.1",
124
+ "svg-spritemap-webpack-plugin": "^4.4.0",
125
+ "svgo": "2.8.0",
124
126
  "tls": "^0.0.1",
125
- "typescript": "^4.4.3",
127
+ "typescript": "^4.6.3",
126
128
  "url-loader": "^4.1.1",
127
129
  "util": "^0.12.4",
128
- "webpack": "5.53.0",
129
- "webpack-bundle-analyzer": "^4.4.1",
130
- "webpack-cli": "^4.8.0",
130
+ "webpack": "5.70.0",
131
+ "webpack-bundle-analyzer": "^4.5.0",
132
+ "webpack-cli": "^4.9.2",
131
133
  "webpack-merge": "^5.8.0",
132
134
  "webpack-nano": "^1.1.1",
133
- "webpack-plugin-serve": "^1.5.0"
135
+ "webpack-plugin-serve": "^1.6.0"
134
136
  },
135
137
  "devDependencies": {
136
- "@nlabs/execa-mock": "^1.29.0",
137
- "@types/jest": "^27.0.1",
138
- "@types/luxon": "^2.0.4",
139
- "@types/node": "^16.9.4",
138
+ "@nlabs/execa-mock": "^1.31.0",
139
+ "@types/jest": "^27.4.1",
140
+ "@types/luxon": "^2.3.1",
141
+ "@types/node": "^17.0.23",
140
142
  "@types/ora": "^3.2.0",
141
- "@types/react": "^17.0.22",
143
+ "@types/react": "^17.0.43",
142
144
  "@types/webpack": "^5.28.0",
143
- "eslint": "^7.32.0",
144
- "eslint-config-styleguidejs": "^1.5.3",
145
+ "eslint": "^8.12.0",
146
+ "eslint-config-styleguidejs": "^1.6.0",
145
147
  "lerna": "^4.0.0"
146
148
  },
147
- "gitHead": "e023bf2c59248b153aff3ac14d6411ba1ad176f5"
149
+ "gitHead": "2a250242052c4fee03e8abfd4a5920ebfb40b63c"
148
150
  }
@@ -5,7 +5,7 @@
5
5
  "declaration": true,
6
6
  "esModuleInterop": true,
7
7
  "inlineSourceMap": true,
8
- "jsx": "react",
8
+ "jsx": "react-jsx",
9
9
  "lib": [
10
10
  "es6",
11
11
  "es7",
package/webpack.config.js CHANGED
@@ -19,7 +19,7 @@ const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
19
19
  const {merge} = require('webpack-merge');
20
20
  const {WebpackPluginServe} = require('webpack-plugin-serve');
21
21
 
22
- const {getNodePath, relativeFilePath} = require('./dist/utils');
22
+ const {getNodePath, relativeFilePath} = require('./dist/utils/file');
23
23
 
24
24
  const {ProgressPlugin, ProvidePlugin} = webpack;
25
25
  const isProduction = process.env.NODE_ENV === 'production';
@@ -34,7 +34,7 @@ const {
34
34
  libraryName,
35
35
  libraryTarget,
36
36
  preset,
37
- targetEnvironment,
37
+ targetEnvironment = 'es2015',
38
38
  webpack: webpackCustom
39
39
  } = lexConfig;
40
40
 
@@ -50,13 +50,15 @@ const plugins = [
50
50
  new DotenvPlugin({path: path.resolve(process.cwd(), '.env'), systemvars: false})
51
51
  ];
52
52
 
53
- const target = preset || targetEnvironment;
54
- const isWeb = target === 'web';
53
+ const isWeb = (preset || targetEnvironment) === 'web';
55
54
 
56
55
  if(isWeb) {
57
56
  plugins.push(
58
57
  new CompressionWebpackPlugin({algorithm: 'gzip'}),
59
- new ProvidePlugin({process: 'process/browser'})
58
+ new ProvidePlugin({
59
+ process: 'process/browser',
60
+ React: path.resolve(__dirname, './node_modules/react')
61
+ })
60
62
  );
61
63
  }
62
64
 
@@ -72,6 +74,9 @@ const svgPaths = `${sourceFullPath}/icons/**/**.svg`;
72
74
 
73
75
  if(glob.sync(svgPaths, globOptions).length) {
74
76
  plugins.push(new SVGSpritemapPlugin(svgPaths, {
77
+ input: {
78
+ allowDuplicates: false
79
+ },
75
80
  output: {
76
81
  chunk: {keep: true},
77
82
  filename: './icons/icons.svg'
@@ -144,6 +149,7 @@ const aliasPaths = {
144
149
  '@nlabs/arkhamjs': relativeFilePath('node_modules/@nlabs/arkhamjs', process.cwd()),
145
150
  '@nlabs/arkhamjs-utils-react': relativeFilePath('node_modules/@nlabs/arkhamjs-utils-react', process.cwd()),
146
151
  'core-js': getNodePath('core-js'),
152
+ process: relativeFilePath('node_modules/process', process.cwd()),
147
153
  react: relativeFilePath('node_modules/react', process.cwd()),
148
154
  'react-dom': relativeFilePath('node_modules/react-dom', process.cwd()),
149
155
  'regenerator-runtime': getNodePath('regenerator-runtime')
@@ -194,7 +200,10 @@ module.exports = (webpackEnv, webpackOptions) => {
194
200
  loader: esbuildLoaderPath,
195
201
  options: {
196
202
  loader: 'tsx',
197
- target: 'es2015'
203
+ target: targetEnvironment === 'node' ? 'node14' : 'es2016'
204
+ },
205
+ resolve: {
206
+ symlinks: true
198
207
  },
199
208
  test: /\.(ts|tsx|js)$/
200
209
  },
@@ -282,7 +291,7 @@ module.exports = (webpackEnv, webpackOptions) => {
282
291
  minimizer: [
283
292
  new ESBuildMinifyPlugin({
284
293
  css: true,
285
- target: 'es2015'
294
+ target: targetEnvironment
286
295
  })
287
296
  ],
288
297
  runtimeChunk: 'single',
@@ -328,17 +337,13 @@ module.exports = (webpackEnv, webpackOptions) => {
328
337
  node_modules: true
329
338
  }
330
339
  },
331
- // stats: {
332
- // warningsFilter: [/Failed to parse source map/]
333
- // },
334
- target
340
+ target: isWeb ? 'web' : 'node'
335
341
  };
336
342
 
337
343
  // Add development plugins
338
344
  if(!isProduction) {
339
345
  webpackConfig.resolve.alias = {
340
346
  ...webpackConfig.resolve.alias,
341
- 'react-dom': relativeFilePath('node_modules/@hot-loader/react-dom', __dirname),
342
347
  webpack: webpackPath
343
348
  };
344
349
  webpackConfig.optimization = {minimize: false};
@@ -353,7 +358,14 @@ module.exports = (webpackEnv, webpackOptions) => {
353
358
  disableDotRule: true,
354
359
  htmlAcceptHeaders: ['text/html','*/*'],
355
360
  index: '/index.html',
361
+ logger: console.log.bind(console),
356
362
  rewrites: [
363
+ // wps
364
+ {
365
+ from: '/wps',
366
+ to: ({parsedUrl: {pathname}}) => pathname
367
+ },
368
+
357
369
  // Javascript files
358
370
  {
359
371
  from: /\.js/,
@@ -364,7 +376,7 @@ module.exports = (webpackEnv, webpackOptions) => {
364
376
  }
365
377
  },
366
378
 
367
- // Other static files
379
+ // Static files
368
380
  {
369
381
  from: /\.[css,gif,ico,jpg,json,png,svg]/,
370
382
  to: ({parsedUrl: {pathname}}) => pathname
@@ -374,8 +386,15 @@ module.exports = (webpackEnv, webpackOptions) => {
374
386
  },
375
387
  hmr: false,
376
388
  log: {level: 'trace'},
389
+ middleware: (app) => app.use(async (ctx, next) => {
390
+ if(ctx.path.match(/^\/wps/)) {
391
+ const {accept, Accept, ...remainingHeaders} = ctx.request.header;
392
+ ctx.request.header = remainingHeaders;
393
+ }
394
+ await next();
395
+ }),
377
396
  open: process.env.WEBPACK_DEV_OPEN === 'true',
378
- port: 7000,
397
+ port: 7001,
379
398
  progress: 'minimal',
380
399
  static: [outputFullPath],
381
400
  status: true
@@ -388,7 +407,7 @@ module.exports = (webpackEnv, webpackOptions) => {
388
407
 
389
408
  if(watch) {
390
409
  webpackConfig.bail = false;
391
- webpackConfig.watch = true;
410
+ // webpackConfig.watch = true;
392
411
  webpackConfig.watchOptions = {
393
412
  aggregateTimeout: 500,
394
413
  ignored: ['node_modules/**', ...watchIgnorePaths]
package/dist/utils.js DELETED
@@ -1,306 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
22
- var __export = (target, all) => {
23
- __markAsModule(target);
24
- for (var name in all)
25
- __defProp(target, name, { get: all[name], enumerable: true });
26
- };
27
- var __reExport = (target, module2, desc) => {
28
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
29
- for (let key of __getOwnPropNames(module2))
30
- if (!__hasOwnProp.call(target, key) && key !== "default")
31
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
32
- }
33
- return target;
34
- };
35
- var __toModule = (module2) => {
36
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
37
- };
38
- __export(exports, {
39
- checkLinkedModules: () => checkLinkedModules,
40
- copyFileSync: () => copyFileSync,
41
- copyFiles: () => copyFiles,
42
- copyFolderRecursiveSync: () => copyFolderRecursiveSync,
43
- createSpinner: () => createSpinner,
44
- cwd: () => cwd,
45
- getFilenames: () => getFilenames,
46
- getFilesByExt: () => getFilesByExt,
47
- getNodePath: () => getNodePath,
48
- getPackageJson: () => getPackageJson,
49
- linkedModules: () => linkedModules,
50
- log: () => log,
51
- relativeFilePath: () => relativeFilePath,
52
- removeConflictModules: () => removeConflictModules,
53
- removeFiles: () => removeFiles,
54
- removeModules: () => removeModules,
55
- setPackageJson: () => setPackageJson,
56
- updateTemplateName: () => updateTemplateName
57
- });
58
- var import_boxen = __toModule(require("boxen"));
59
- var import_chalk = __toModule(require("chalk"));
60
- var import_find_file_up = __toModule(require("find-file-up"));
61
- var import_fs_extra = __toModule(require("fs-extra"));
62
- var import_glob = __toModule(require("glob"));
63
- var import_isEmpty = __toModule(require("lodash/isEmpty"));
64
- var import_ora = __toModule(require("ora"));
65
- var import_path = __toModule(require("path"));
66
- var import_rimraf = __toModule(require("rimraf"));
67
- var import_LexConfig = __toModule(require("./LexConfig"));
68
- const cwd = process.cwd();
69
- const log = (message, type = "info", quiet = false) => {
70
- if (!quiet) {
71
- let color;
72
- switch (type) {
73
- case "error":
74
- color = import_chalk.default.red;
75
- break;
76
- case "note":
77
- color = import_chalk.default.grey;
78
- break;
79
- case "success":
80
- color = import_chalk.default.greenBright;
81
- break;
82
- case "warn":
83
- color = import_chalk.default.yellow;
84
- break;
85
- default:
86
- color = import_chalk.default.cyan;
87
- break;
88
- }
89
- console.log(color(message));
90
- }
91
- };
92
- const getFilenames = (props) => {
93
- const { callback, cliName, name, quiet, type, useTypescript } = props;
94
- let nameCaps;
95
- const itemTypes = ["stores", "views"];
96
- if (!name) {
97
- if (itemTypes.includes(type)) {
98
- log(`
99
- ${cliName} Error: ${type} name is required. Please use 'lex -h' for options.`, "error", quiet);
100
- return callback(1);
101
- }
102
- } else {
103
- nameCaps = `${name.charAt(0).toUpperCase()}${name.substr(1)}`;
104
- }
105
- log(`${cliName} adding ${name} ${type}...`, "info", quiet);
106
- let templatePath;
107
- let templateExt;
108
- let templateReact;
109
- if (useTypescript) {
110
- templatePath = "../../templates/typescript";
111
- templateExt = ".ts";
112
- templateReact = ".tsx";
113
- } else {
114
- templatePath = "../../templates/flow";
115
- templateExt = ".js";
116
- templateReact = ".js";
117
- }
118
- return {
119
- nameCaps,
120
- templateExt,
121
- templatePath,
122
- templateReact
123
- };
124
- };
125
- const createSpinner = (quiet = false) => {
126
- if (quiet) {
127
- return {
128
- fail: () => {
129
- },
130
- start: () => {
131
- },
132
- succeed: () => {
133
- }
134
- };
135
- }
136
- return (0, import_ora.default)({ color: "yellow" });
137
- };
138
- const copyFiles = async (files, typeName, spinner) => {
139
- const { outputFullPath, sourceFullPath } = import_LexConfig.LexConfig.config;
140
- const items = files.map((fileName) => ({
141
- from: fileName,
142
- to: import_path.default.resolve(outputFullPath, import_path.default.relative(sourceFullPath, fileName))
143
- }));
144
- try {
145
- spinner.start(`Copying ${typeName} files...`);
146
- await Promise.all(items.map(({ from, to }) => import_fs_extra.default.copy(from, to)));
147
- spinner.succeed(`Successfully copied ${files.length} ${typeName} files!`);
148
- } catch (error) {
149
- spinner.fail(`Copying of ${typeName} files failed.`);
150
- log(`Error: ${error.message}`, "error");
151
- console.log(error);
152
- }
153
- };
154
- const copyFileSync = (source, target) => {
155
- let targetFile = target;
156
- if (import_fs_extra.default.existsSync(target)) {
157
- if (import_fs_extra.default.lstatSync(target).isDirectory()) {
158
- targetFile = import_path.default.join(target, import_path.default.basename(source));
159
- }
160
- }
161
- import_fs_extra.default.writeFileSync(targetFile, import_fs_extra.default.readFileSync(source));
162
- };
163
- const copyFolderRecursiveSync = (source, target) => {
164
- let files = [];
165
- const targetFolder = import_path.default.join(target, import_path.default.basename(source));
166
- if (!import_fs_extra.default.existsSync(targetFolder)) {
167
- import_fs_extra.default.mkdirSync(targetFolder);
168
- }
169
- if (import_fs_extra.default.lstatSync(source).isDirectory()) {
170
- files = import_fs_extra.default.readdirSync(source);
171
- files.forEach((file) => {
172
- const curSource = import_path.default.join(source, file);
173
- if (import_fs_extra.default.lstatSync(curSource).isDirectory()) {
174
- copyFolderRecursiveSync(curSource, targetFolder);
175
- } else {
176
- copyFileSync(curSource, targetFolder);
177
- }
178
- });
179
- }
180
- };
181
- const getPackageJson = (packagePath) => {
182
- const formatPath = packagePath || `${process.cwd()}/package.json`;
183
- const packageData = import_fs_extra.default.readFileSync(formatPath).toString();
184
- return JSON.parse(packageData);
185
- };
186
- const getFilesByExt = (ext) => {
187
- const { sourceFullPath } = import_LexConfig.LexConfig.config;
188
- return import_glob.default.sync(`${sourceFullPath}/**/**${ext}`);
189
- };
190
- const removeConflictModules = (moduleList) => {
191
- const updatedList = __spreadValues({}, moduleList);
192
- Object.keys(updatedList).forEach((moduleName) => {
193
- const regex = new RegExp("^(?!@types/).*(jest|webpack).*$", "gi");
194
- if (regex.test(moduleName)) {
195
- delete updatedList[moduleName];
196
- }
197
- });
198
- return updatedList;
199
- };
200
- const removeFiles = (fileName, isRelative = false) => new Promise((resolve, reject) => {
201
- const filePath = isRelative ? import_path.default.resolve(cwd, fileName) : fileName;
202
- (0, import_rimraf.default)(filePath, (error) => {
203
- if (error) {
204
- return reject(error);
205
- }
206
- return resolve(null);
207
- });
208
- });
209
- const removeModules = () => new Promise(async (resolve, reject) => {
210
- try {
211
- await removeFiles("./node_modules", true);
212
- await removeFiles("./yarn.lock", true);
213
- await removeFiles("./package-lock.json", true);
214
- resolve(null);
215
- } catch (error) {
216
- reject(error);
217
- }
218
- });
219
- const setPackageJson = (json, packagePath) => {
220
- if (!json) {
221
- return;
222
- }
223
- const formatPath = packagePath || `${process.cwd()}/package.json`;
224
- import_fs_extra.default.writeFileSync(formatPath, JSON.stringify(json, null, 2));
225
- };
226
- const linkedModules = (startPath) => {
227
- const workingPath = startPath || process.cwd();
228
- let modulePath;
229
- let prefix;
230
- if (workingPath.includes("@")) {
231
- prefix = `@${workingPath.split("@").pop()}`;
232
- modulePath = workingPath;
233
- } else {
234
- modulePath = import_path.default.join(workingPath, "node_modules");
235
- }
236
- const foundPaths = import_glob.default.sync(`${modulePath}/*`);
237
- return foundPaths.reduce((list, foundPath) => {
238
- try {
239
- const stats = import_fs_extra.default.lstatSync(foundPath);
240
- if (stats.isDirectory()) {
241
- const deepList = linkedModules(foundPath);
242
- list.push(...deepList);
243
- } else if (stats.isSymbolicLink()) {
244
- const moduleNames = [prefix, import_path.default.basename(foundPath)].filter((item) => !(0, import_isEmpty.default)(item));
245
- list.push({ name: `${moduleNames.join("/")}`, path: foundPath });
246
- }
247
- return list;
248
- } catch (fsError) {
249
- throw fsError;
250
- }
251
- }, []);
252
- };
253
- const checkLinkedModules = () => {
254
- const linked = linkedModules();
255
- if (linked.length) {
256
- const msgModule = linked.length > 1 ? "Modules" : "Module";
257
- const linkedMsg = linked.reduce((msg, linkedModule) => `${msg}
258
- * ${linkedModule.name}`, `Linked ${msgModule}:`);
259
- log((0, import_boxen.default)(linkedMsg, { dimBorder: true, padding: 1 }), "warn");
260
- }
261
- };
262
- const relativeFilePath = (filename, nodePath = "./", backUp = 0) => {
263
- const nestDepth = 10;
264
- if (backUp) {
265
- const filePath = import_find_file_up.default.sync(filename, nodePath, nestDepth);
266
- const previousPath = Array(backUp).fill(null).map(() => "../").join("");
267
- return import_path.default.resolve(filePath, previousPath);
268
- }
269
- return import_find_file_up.default.sync(filename, nodePath, nestDepth);
270
- };
271
- const getNodePath = (moduleName) => {
272
- const modulePath = `node_modules/${moduleName}`;
273
- const repoPath = import_find_file_up.default.sync(modulePath, __dirname);
274
- if (repoPath && import_fs_extra.default.existsSync(repoPath)) {
275
- return repoPath;
276
- }
277
- const localPath = import_find_file_up.default.sync(modulePath, "./", 10) || `./${modulePath}`;
278
- return localPath;
279
- };
280
- const updateTemplateName = (filePath, replace, replaceCaps) => {
281
- let data = import_fs_extra.default.readFileSync(filePath, "utf8");
282
- data = data.replace(/sample/g, replace);
283
- data = data.replace(/Sample/g, replaceCaps);
284
- import_fs_extra.default.writeFileSync(filePath, data, "utf8");
285
- };
286
- // Annotate the CommonJS export names for ESM import in node:
287
- 0 && (module.exports = {
288
- checkLinkedModules,
289
- copyFileSync,
290
- copyFiles,
291
- copyFolderRecursiveSync,
292
- createSpinner,
293
- cwd,
294
- getFilenames,
295
- getFilesByExt,
296
- getNodePath,
297
- getPackageJson,
298
- linkedModules,
299
- log,
300
- relativeFilePath,
301
- removeConflictModules,
302
- removeFiles,
303
- removeModules,
304
- setPackageJson,
305
- updateTemplateName
306
- });