@naturalcycles/dev-lib 19.31.1 → 19.33.0

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.
@@ -2,6 +2,7 @@
2
2
  // tsconfig.json for /scripts
3
3
  //
4
4
  {
5
- "extends": "@naturalcycles/dev-lib/scripts/tsconfig.json",
5
+ "extends": "@naturalcycles/dev-lib/cfg/tsconfig.scripts.json",
6
+ "compilerOptions": {},
6
7
  "exclude": ["**/__exclude"]
7
8
  }
@@ -19,7 +19,7 @@ import { execSync } from 'node:child_process'
19
19
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
20
20
  import { semver2 } from '@naturalcycles/js-lib/semver'
21
21
  import { exec2 } from '@naturalcycles/nodejs-lib/exec2'
22
-
22
+ import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
23
23
  import {
24
24
  prettierDirs,
25
25
  prettierExtensionsExclusive,
@@ -39,9 +39,22 @@ const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
39
39
 
40
40
  // const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
41
41
 
42
- const prettierCmd =
43
- !!prettierConfigPath &&
44
- `prettier --write --experimental-cli --config-path ${prettierConfigPath} --cache-location node_modules/.cache/prettier`
42
+ let prettierCmd = undefined
43
+
44
+ if (prettierConfigPath) {
45
+ const experimental = !hasPrettierOverrides()
46
+ prettierCmd = [
47
+ 'prettier --write --log-level=warn',
48
+ experimental && '--cache-location',
49
+ experimental && 'node_modules/.cache/prettier',
50
+ experimental && `--experimental-cli`,
51
+ experimental ? '--config-path' : `--config`,
52
+ prettierConfigPath,
53
+ ]
54
+ .filter(Boolean)
55
+ .join(' ')
56
+ }
57
+
45
58
  const eslintCmd = [
46
59
  'eslint',
47
60
  '--fix',
@@ -222,4 +235,12 @@ function getActionLintVersion() {
222
235
  }
223
236
  }
224
237
 
238
+ function hasPrettierOverrides() {
239
+ try {
240
+ return fs2.readText('prettier.config.js').includes('overrides')
241
+ } catch {
242
+ return false
243
+ }
244
+ }
245
+
225
246
  export default linters
@@ -0,0 +1,15 @@
1
+ //
2
+ // @naturalcycles/dev-lib/cfg/tsconfig.backend.json
3
+ //
4
+ // Shared tsconfig for Backend services
5
+ //
6
+ {
7
+ "compilerOptions": {
8
+ "paths": {
9
+ "@src/*": ["${configDir}/src/*"]
10
+ }
11
+ }
12
+ // Need to be specified in the project tsconfig
13
+ // "include": ["src"],
14
+ // "exclude": ["**/__exclude"]
15
+ }
@@ -0,0 +1,14 @@
1
+ //
2
+ // @naturalcycles/dev-lib/cfg/tsconfig.e2e.json
3
+ //
4
+ {
5
+ "extends": "./tsconfig.json",
6
+ "compilerOptions": {
7
+ "rootDir": "${configDir}/..",
8
+ "baseUrl": "${configDir}",
9
+ "outDir": "${configDir}/../dist/e2e",
10
+ "noEmit": true,
11
+ "tsBuildInfoFile": "${configDir}/../node_modules/.cache/e2e.tsbuildinfo"
12
+ },
13
+ "exclude": ["**/__exclude"]
14
+ }
@@ -0,0 +1,17 @@
1
+ //
2
+ // @naturalcycles/dev-lib/cfg/tsconfig.frontend.json
3
+ //
4
+ // Shared tsconfig for Frontend applications
5
+ //
6
+ {
7
+ "compilerOptions": {
8
+ "noEmit": true,
9
+ "target": "es2023", // es2023+ browsers, adjust to your requirements!
10
+ "lib": ["esnext", "dom", "dom.iterable"],
11
+ "module": "esnext",
12
+ "moduleResolution": "bundler"
13
+ }
14
+ // Need to be specified in the project tsconfig
15
+ // "include": ["src"],
16
+ // "exclude": ["**/__exclude"]
17
+ }
package/cfg/tsconfig.json CHANGED
@@ -5,10 +5,9 @@
5
5
  //
6
6
  {
7
7
  "compilerOptions": {
8
- // ${configDir} is supported since ts 5.5
9
8
  "rootDir": "${configDir}/src",
9
+ "baseUrl": "${configDir}/src",
10
10
  "outDir": "${configDir}/dist",
11
-
12
11
  // Target/module
13
12
  "target": "es2023",
14
13
  "lib": ["esnext"], // add "dom" if needed
@@ -45,17 +44,11 @@
45
44
  "noUncheckedSideEffectImports": true,
46
45
  "noPropertyAccessFromIndexSignature": true,
47
46
 
48
- // todo: monitor if we should have it default or not
49
47
  // Enabled should be faster, but will catch less errors
50
48
  // "skipLibCheck": true,
51
49
 
52
- // Need to be specified in the project tsconfig
53
- // "typeRoots": [
54
- // "node_modules/@types",
55
- // "src/@types"
56
- // ],
57
-
58
50
  // Other
51
+ "jsx": "preserve",
59
52
  "incremental": true,
60
53
  "tsBuildInfoFile": "${configDir}/node_modules/.cache/src.tsbuildinfo",
61
54
  "pretty": true,
@@ -0,0 +1,14 @@
1
+ //
2
+ // @naturalcycles/dev-lib/cfg/tsconfig.scripts.json
3
+ //
4
+ {
5
+ "extends": "./tsconfig.json",
6
+ "compilerOptions": {
7
+ "rootDir": "${configDir}/..",
8
+ "baseUrl": "${configDir}",
9
+ "outDir": "${configDir}/../dist/scripts",
10
+ "noEmit": true,
11
+ "tsBuildInfoFile": "${configDir}/../node_modules/.cache/scripts.tsbuildinfo"
12
+ },
13
+ "exclude": ["**/__exclude"]
14
+ }
@@ -38,7 +38,7 @@ export async function runTSCInFolder(dir, args = []) {
38
38
  const tscPath = findPackageBinPath('typescript', 'tsc');
39
39
  const cacheLocation = `node_modules/.cache/${dir}.tsbuildinfo`;
40
40
  const cacheFound = existsSync(cacheLocation);
41
- console.log(dimGrey(`${check(cacheFound)} tsc ${dir} cache found: ${cacheFound}`));
41
+ console.log(dimGrey(`${check(cacheFound)}tsc ${dir} cache found: ${cacheFound}`));
42
42
  await exec2.spawnAsync(tscPath, {
43
43
  args: ['-P', tsconfigPath, ...args],
44
44
  shell: false,
@@ -74,5 +74,5 @@ export function buildCopy() {
74
74
  });
75
75
  }
76
76
  function check(predicate) {
77
- return predicate ? '✔️ ' : ' ';
77
+ return predicate ? ' ' : ' ';
78
78
  }
package/dist/lint.util.js CHANGED
@@ -8,7 +8,7 @@ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
8
8
  import { _filterFalsyValues } from '@naturalcycles/js-lib/object/object.util.js';
9
9
  import { semver2 } from '@naturalcycles/js-lib/semver';
10
10
  import { git2 } from '@naturalcycles/nodejs-lib';
11
- import { boldGrey, dimGrey } from '@naturalcycles/nodejs-lib/colors';
11
+ import { dimGrey, white } from '@naturalcycles/nodejs-lib/colors';
12
12
  import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
13
13
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
14
14
  import { _yargs } from '@naturalcycles/nodejs-lib/yargs';
@@ -54,7 +54,7 @@ export async function lintAllCommand() {
54
54
  }
55
55
  runPrettier({ fix });
56
56
  await runKTLint(fix);
57
- console.log(`${boldGrey(`${check(true)} lint-all`)} ${dimGrey(`took ` + _since(started))}`);
57
+ console.log(`${check(true)}${white(`lint-all`)} ${dimGrey(`took ` + _since(started))}`);
58
58
  // if (needToTrackChanges) {
59
59
  // const gitStatusAfter = gitStatus()
60
60
  // const hasChanges = gitStatusAfter !== gitStatusAtStart
@@ -110,7 +110,7 @@ export async function eslintAll(opt) {
110
110
  await runESLint(`scripts`, extensions, fix);
111
111
  await runESLint(`e2e`, extensions, fix);
112
112
  }
113
- console.log(`${boldGrey(`${check(true)} eslint-all`)} ${dimGrey(`took ` + _since(started))}`);
113
+ console.log(`${check(true)}${white(`eslint-all`)} ${dimGrey(`took ` + _since(started))}`);
114
114
  }
115
115
  async function runESLint(dir, extensions = eslintExtensions.split(','), fix = true) {
116
116
  let configDir = dir;
@@ -130,7 +130,7 @@ async function runESLint(dir, extensions = eslintExtensions.split(','), fix = tr
130
130
  const eslintPath = findPackageBinPath('eslint', 'eslint');
131
131
  const cacheLocation = `node_modules/.cache/eslint_${dir}`;
132
132
  const cacheFound = existsSync(cacheLocation);
133
- console.log(dimGrey(`${check(cacheFound)} eslint ${dir} cache found: ${cacheFound}`));
133
+ console.log(dimGrey(`${check(cacheFound)}eslint ${dir} cache found: ${cacheFound}`));
134
134
  await exec2.spawnAsync(eslintPath, {
135
135
  name: ['eslint', dir, !fix && '--no-fix'].filter(Boolean).join(' '),
136
136
  args: [
@@ -164,22 +164,27 @@ const prettierPaths = [
164
164
  ...lintExclude.map((s) => `!${s}`),
165
165
  ];
166
166
  export function runPrettier(opt = {}) {
167
- const { experimentalCli = true, fix = true } = opt;
167
+ let { experimentalCli = true, fix = true } = opt;
168
168
  const prettierConfigPath = [`./prettier.config.js`].find(f => existsSync(f));
169
169
  if (!prettierConfigPath)
170
170
  return;
171
171
  const prettierPath = findPackageBinPath('prettier', 'prettier');
172
172
  const cacheLocation = 'node_modules/.cache/prettier';
173
173
  const cacheFound = existsSync(cacheLocation);
174
- console.log(dimGrey(`${check(cacheFound)} prettier cache found: ${cacheFound}`));
174
+ console.log(dimGrey(`${check(cacheFound)}prettier cache found: ${cacheFound}`));
175
+ if (hasPrettierOverrides()) {
176
+ experimentalCli = false;
177
+ console.log(' prettier experimental mode disabled due to "overrides" in prettier.config.js');
178
+ }
175
179
  // prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
176
180
  exec2.spawn(prettierPath, {
177
181
  name: fix ? 'prettier' : 'prettier --check',
178
182
  args: [
179
183
  fix ? `--write` : '--check',
180
184
  `--log-level=warn`,
181
- '--cache-location',
182
- cacheLocation,
185
+ // non-experimental-cli has different cache format, hence disabling it
186
+ experimentalCli && '--cache-location',
187
+ experimentalCli && cacheLocation,
183
188
  experimentalCli && `--experimental-cli`,
184
189
  experimentalCli ? '--config-path' : `--config`,
185
190
  prettierConfigPath,
@@ -309,6 +314,14 @@ export function findPackageBinPath(pkg, cmd) {
309
314
  const { bin } = fs2.readJson(packageJsonPath);
310
315
  return path.join(path.dirname(packageJsonPath), typeof bin === 'string' ? bin : bin[cmd]);
311
316
  }
317
+ function hasPrettierOverrides() {
318
+ try {
319
+ return fs2.readText('prettier.config.js').includes('overrides');
320
+ }
321
+ catch {
322
+ return false;
323
+ }
324
+ }
312
325
  function check(predicate) {
313
- return predicate ? '✔️ ' : ' ';
326
+ return predicate ? ' ' : ' ';
314
327
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "19.31.1",
4
+ "version": "19.33.0",
5
5
  "dependencies": {
6
6
  "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^19",
@@ -53,8 +53,11 @@
53
53
  "./cfg/prettier.config.js": "./cfg/prettier.config.js",
54
54
  "./cfg/stylelint.config.js": "./cfg/stylelint.config.js",
55
55
  "./cfg/tsconfig.json": "./cfg/tsconfig.json",
56
+ "./cfg/tsconfig.scripts.json": "./cfg/tsconfig.scripts.json",
57
+ "./cfg/tsconfig.e2e.json": "./cfg/tsconfig.e2e.json",
58
+ "./cfg/tsconfig.backend.json": "./cfg/tsconfig.backend.json",
59
+ "./cfg/tsconfig.frontend.json": "./cfg/tsconfig.frontend.json",
56
60
  "./cfg/vitest.config.js": "./cfg/vitest.config.js",
57
- "./scripts/tsconfig.json": "./scripts/tsconfig.json",
58
61
  ".": "./dist/index.js",
59
62
  "./testing": "./dist/testing/index.js",
60
63
  "./testing/time": "./dist/testing/time.js",
@@ -2,12 +2,7 @@
2
2
  // tsconfig.json for /scripts
3
3
  //
4
4
  {
5
- "extends": "../cfg/tsconfig.json",
6
- "compilerOptions": {
7
- "rootDir": "${configDir}/..",
8
- "outDir": "${configDir}/../dist/scripts",
9
- "noEmit": true,
10
- "tsBuildInfoFile": "${configDir}/../node_modules/.cache/scripts.tsbuildinfo"
11
- },
5
+ "extends": "../cfg/tsconfig.scripts.json",
6
+ "compilerOptions": {},
12
7
  "exclude": ["**/__exclude"]
13
8
  }