@powerlines/nx 0.5.0 → 0.5.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/CHANGELOG.md +7 -0
- package/dist/{chunk-GPR4LRJV.js → chunk-6COOH7PT.js} +2 -2
- package/dist/{chunk-E5KDMPYX.mjs → chunk-6EYSDBXF.mjs} +1 -1
- package/dist/{chunk-5DSETHHW.js → chunk-BJ4E5KUK.js} +2 -2
- package/dist/{chunk-CNNNEVWJ.mjs → chunk-FQGP7LHQ.mjs} +1 -1
- package/dist/{chunk-LRONVULK.js → chunk-FW5WOOGV.js} +141 -613
- package/dist/{chunk-RK2TJCMI.js → chunk-ID7Q55KI.js} +2 -2
- package/dist/{chunk-THDQE26D.mjs → chunk-K2URIO44.mjs} +1 -1
- package/dist/{chunk-2KAWJURA.js → chunk-QARFJCME.js} +2 -2
- package/dist/{chunk-UQ4OVGQQ.mjs → chunk-RVNLAQU5.mjs} +133 -604
- package/dist/{chunk-J2XU6B3K.js → chunk-USVD3RLO.js} +2 -2
- package/dist/{chunk-KO42I6KA.mjs → chunk-V73NN5FH.mjs} +1 -1
- package/dist/{chunk-QAEGJGQS.mjs → chunk-YZ7FHAGJ.mjs} +1 -1
- package/dist/executors.js +11 -11
- package/dist/executors.mjs +6 -6
- package/dist/index.js +11 -11
- package/dist/index.mjs +6 -6
- package/dist/src/base/base-executor.js +2 -2
- package/dist/src/base/base-executor.mjs +1 -1
- package/dist/src/executors/build/executor.js +4 -4
- package/dist/src/executors/build/executor.mjs +2 -2
- package/dist/src/executors/clean/executor.js +4 -4
- package/dist/src/executors/clean/executor.mjs +2 -2
- package/dist/src/executors/docs/executor.js +4 -4
- package/dist/src/executors/docs/executor.mjs +2 -2
- package/dist/src/executors/lint/executor.js +4 -4
- package/dist/src/executors/lint/executor.mjs +2 -2
- package/dist/src/executors/prepare/executor.js +4 -4
- package/dist/src/executors/prepare/executor.mjs +2 -2
- package/package.json +5 -5
|
@@ -26,7 +26,7 @@ import chalk5 from 'chalk';
|
|
|
26
26
|
import Handlebars from 'handlebars';
|
|
27
27
|
import { readJsonFile, readJsonFileSync } from '@stryke/fs/json';
|
|
28
28
|
import { appendPath } from '@stryke/path/append';
|
|
29
|
-
import
|
|
29
|
+
import ts2, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
|
|
30
30
|
import { titleCase } from '@stryke/string-format/title-case';
|
|
31
31
|
import { isUndefined } from '@stryke/type-checks/is-undefined';
|
|
32
32
|
import { writeFile as writeFile$1 } from '@stryke/fs/write-file';
|
|
@@ -54,20 +54,15 @@ import { Blob } from 'node:buffer';
|
|
|
54
54
|
import fs from 'node:fs';
|
|
55
55
|
import { Union } from 'unionfs';
|
|
56
56
|
import { isObject } from '@stryke/type-checks/is-object';
|
|
57
|
-
import { isDirectory } from '@stryke/fs/is-file';
|
|
58
|
-
import { readFile, readFileIfExistingSync } from '@stryke/fs/read-file';
|
|
59
|
-
import { parseVersion } from '@stryke/fs/semver-fns';
|
|
60
|
-
import { getParentPath } from '@stryke/path/get-parent-path';
|
|
61
|
-
import path from 'node:path';
|
|
62
|
-
import { hasPackageVersion, getPackageName, getPackageVersion } from '@stryke/string-format/package';
|
|
63
57
|
import { transformAsync } from '@babel/core';
|
|
58
|
+
import { readFileIfExistingSync } from '@stryke/fs/read-file';
|
|
64
59
|
import MagicString from 'magic-string';
|
|
65
60
|
import { declare } from '@babel/helper-plugin-utils';
|
|
66
61
|
import * as t from '@babel/types';
|
|
62
|
+
import { getPackageName, hasPackageVersion, getPackageVersion } from '@stryke/string-format/package';
|
|
67
63
|
import { getObjectDiff } from '@donedeal0/superdiff';
|
|
68
64
|
import { loadTsConfig } from '@stryke/fs/tsconfig';
|
|
69
65
|
import { StormJSON } from '@stryke/json/storm-json';
|
|
70
|
-
import { minimatch } from 'minimatch';
|
|
71
66
|
import { isDevelopmentMode, isTestMode } from '@stryke/env/environment-checks';
|
|
72
67
|
import { createVitePlugin, createEsbuildPlugin, createWebpackPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin } from 'unplugin';
|
|
73
68
|
import { match, tsconfigPathsToRegExp } from 'bundle-require';
|
|
@@ -135,13 +130,13 @@ function isIncludeMatchFound(tsconfigType, types) {
|
|
|
135
130
|
return findIncludeMatch(tsconfigType, types) !== void 0;
|
|
136
131
|
}
|
|
137
132
|
__name(isIncludeMatchFound, "isIncludeMatchFound");
|
|
138
|
-
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host =
|
|
133
|
+
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host = ts2.sys) {
|
|
139
134
|
const tsconfigFilePath = getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
|
|
140
135
|
const tsconfigJson = readJsonFileSync(tsconfigFilePath);
|
|
141
136
|
if (!tsconfigJson) {
|
|
142
137
|
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
|
|
143
138
|
}
|
|
144
|
-
const parsedCommandLine =
|
|
139
|
+
const parsedCommandLine = ts2.parseJsonConfigFileContent(defu4(tsconfigRaw ?? {}, tsconfigJson), host, appendPath(projectRoot, workspaceRoot));
|
|
145
140
|
if (parsedCommandLine.errors.length > 0) {
|
|
146
141
|
const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
|
|
147
142
|
${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
|
|
@@ -590,7 +585,7 @@ var VirtualFileSystem = class {
|
|
|
590
585
|
* @returns `true` if the path or ID corresponds to a runtime file, otherwise `false`.
|
|
591
586
|
*/
|
|
592
587
|
isBuiltinFile(pathOrId, options) {
|
|
593
|
-
return !!this.builtinIdMap.values().find((
|
|
588
|
+
return !!this.builtinIdMap.values().find((path) => path === this.resolvePath(pathOrId, {
|
|
594
589
|
...options,
|
|
595
590
|
type: "file"
|
|
596
591
|
}));
|
|
@@ -622,7 +617,7 @@ var VirtualFileSystem = class {
|
|
|
622
617
|
if (!resolvedPath) {
|
|
623
618
|
return false;
|
|
624
619
|
}
|
|
625
|
-
if (this.builtinIdMap.values().find((
|
|
620
|
+
if (this.builtinIdMap.values().find((path) => path === resolvedPath)) {
|
|
626
621
|
return true;
|
|
627
622
|
}
|
|
628
623
|
return this.#virtualFS.existsSync(resolvedPath);
|
|
@@ -636,7 +631,7 @@ var VirtualFileSystem = class {
|
|
|
636
631
|
* @returns Whether the path or ID corresponds to a virtual file.
|
|
637
632
|
*/
|
|
638
633
|
isTsconfigPath(pathOrId) {
|
|
639
|
-
return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((
|
|
634
|
+
return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path) => pathOrId.startsWith(path.replaceAll("*", "")));
|
|
640
635
|
}
|
|
641
636
|
/**
|
|
642
637
|
* Checks if a given ID corresponds to a runtime file path.
|
|
@@ -657,12 +652,12 @@ var VirtualFileSystem = class {
|
|
|
657
652
|
*/
|
|
658
653
|
async listBuiltinFiles() {
|
|
659
654
|
const runtimeFiles = [];
|
|
660
|
-
for (const [id,
|
|
661
|
-
const contents = await this.readFile(
|
|
655
|
+
for (const [id, path] of this.builtinIdMap.entries()) {
|
|
656
|
+
const contents = await this.readFile(path);
|
|
662
657
|
if (contents) {
|
|
663
658
|
runtimeFiles.push({
|
|
664
659
|
id: this.formatRuntimeId(id),
|
|
665
|
-
path
|
|
660
|
+
path,
|
|
666
661
|
contents
|
|
667
662
|
});
|
|
668
663
|
}
|
|
@@ -676,21 +671,21 @@ var VirtualFileSystem = class {
|
|
|
676
671
|
* @param options - Options for listing files, such as encoding and recursion.
|
|
677
672
|
* @returns An array of file names in the specified path.
|
|
678
673
|
*/
|
|
679
|
-
readdirSync(
|
|
680
|
-
return this.resolveFS(
|
|
674
|
+
readdirSync(path, options = "utf8") {
|
|
675
|
+
return this.resolveFS(path).readdirSync(toFilePath(path), options);
|
|
681
676
|
}
|
|
682
677
|
/**
|
|
683
678
|
* Removes a file in the virtual file system (VFS).
|
|
684
679
|
*
|
|
685
680
|
* @param path - The path to create the directory at.
|
|
686
681
|
*/
|
|
687
|
-
unlinkSync(
|
|
688
|
-
const formattedPath = toFilePath(
|
|
689
|
-
if (!this.fileExistsSync(
|
|
682
|
+
unlinkSync(path, options) {
|
|
683
|
+
const formattedPath = toFilePath(path);
|
|
684
|
+
if (!this.fileExistsSync(path)) {
|
|
690
685
|
return;
|
|
691
686
|
}
|
|
692
687
|
this.#log(LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
|
|
693
|
-
this.resolveFS(
|
|
688
|
+
this.resolveFS(path, options).unlinkSync(formattedPath);
|
|
694
689
|
this.#cachedFS.delete(formattedPath);
|
|
695
690
|
this.clearResolverCache(formattedPath);
|
|
696
691
|
}
|
|
@@ -699,14 +694,14 @@ var VirtualFileSystem = class {
|
|
|
699
694
|
*
|
|
700
695
|
* @param path - The path to create the directory at.
|
|
701
696
|
*/
|
|
702
|
-
async unlink(
|
|
703
|
-
const formattedPath = toFilePath(
|
|
704
|
-
if (!this.fileExistsSync(
|
|
697
|
+
async unlink(path, options) {
|
|
698
|
+
const formattedPath = toFilePath(path);
|
|
699
|
+
if (!this.fileExistsSync(path)) {
|
|
705
700
|
return;
|
|
706
701
|
}
|
|
707
702
|
this.#log(LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
|
|
708
|
-
if (isFunction(this.resolveFS(
|
|
709
|
-
await this.resolveFS(
|
|
703
|
+
if (isFunction(this.resolveFS(path, options).promises.unlink)) {
|
|
704
|
+
await this.resolveFS(path, options).promises.unlink(formattedPath);
|
|
710
705
|
this.#cachedFS.delete(formattedPath);
|
|
711
706
|
this.clearResolverCache(formattedPath);
|
|
712
707
|
} else {
|
|
@@ -719,13 +714,13 @@ var VirtualFileSystem = class {
|
|
|
719
714
|
* @param path - The path to create the directory at.
|
|
720
715
|
* @param options - Options for creating the directory.
|
|
721
716
|
*/
|
|
722
|
-
rmdirSync(
|
|
723
|
-
const formattedPath = toFilePath(
|
|
724
|
-
if (!this.directoryExistsSync(
|
|
717
|
+
rmdirSync(path, options = {}) {
|
|
718
|
+
const formattedPath = toFilePath(path);
|
|
719
|
+
if (!this.directoryExistsSync(path)) {
|
|
725
720
|
return;
|
|
726
721
|
}
|
|
727
722
|
this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
|
|
728
|
-
this.resolveFS(
|
|
723
|
+
this.resolveFS(path, options).rmdirSync(formattedPath, defu4(options, {
|
|
729
724
|
recursive: true
|
|
730
725
|
}));
|
|
731
726
|
this.#cachedFS.delete(formattedPath);
|
|
@@ -738,14 +733,14 @@ var VirtualFileSystem = class {
|
|
|
738
733
|
* @param options - Options for creating the directory.
|
|
739
734
|
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
740
735
|
*/
|
|
741
|
-
async rmdir(
|
|
742
|
-
const formattedPath = toFilePath(
|
|
743
|
-
if (!this.directoryExistsSync(
|
|
736
|
+
async rmdir(path, options = {}) {
|
|
737
|
+
const formattedPath = toFilePath(path);
|
|
738
|
+
if (!this.directoryExistsSync(path)) {
|
|
744
739
|
return;
|
|
745
740
|
}
|
|
746
741
|
this.#log(LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
|
|
747
|
-
if (isFunction(this.resolveFS(
|
|
748
|
-
await this.resolveFS(
|
|
742
|
+
if (isFunction(this.resolveFS(path, options).promises.rm)) {
|
|
743
|
+
await this.resolveFS(path, options).promises.rm(formattedPath, defu4(options, {
|
|
749
744
|
force: true,
|
|
750
745
|
recursive: true
|
|
751
746
|
}));
|
|
@@ -765,12 +760,12 @@ var VirtualFileSystem = class {
|
|
|
765
760
|
* @param options - Options for removing the file.
|
|
766
761
|
* @returns A promise that resolves when the file is removed.
|
|
767
762
|
*/
|
|
768
|
-
async rm(
|
|
769
|
-
this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(
|
|
770
|
-
if (this.directoryExistsSync(
|
|
771
|
-
return this.rmdir(
|
|
763
|
+
async rm(path, options = {}) {
|
|
764
|
+
this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
|
|
765
|
+
if (this.directoryExistsSync(path)) {
|
|
766
|
+
return this.rmdir(path, options);
|
|
772
767
|
}
|
|
773
|
-
return this.unlink(
|
|
768
|
+
return this.unlink(path, options);
|
|
774
769
|
}
|
|
775
770
|
/**
|
|
776
771
|
* Creates a directory in the virtual file system (VFS).
|
|
@@ -779,8 +774,8 @@ var VirtualFileSystem = class {
|
|
|
779
774
|
* @param options - Options for creating the directory.
|
|
780
775
|
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
781
776
|
*/
|
|
782
|
-
mkdirSync(
|
|
783
|
-
const filePath = toFilePath(
|
|
777
|
+
mkdirSync(path, options = {}) {
|
|
778
|
+
const filePath = toFilePath(path);
|
|
784
779
|
this.clearResolverCache(filePath);
|
|
785
780
|
return this.resolveFS(filePath, options).mkdirSync(filePath, defu4(options ?? {}, {
|
|
786
781
|
recursive: true
|
|
@@ -793,9 +788,9 @@ var VirtualFileSystem = class {
|
|
|
793
788
|
* @param options - Options for creating the directory.
|
|
794
789
|
* @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
|
|
795
790
|
*/
|
|
796
|
-
async mkdir(
|
|
791
|
+
async mkdir(path, options = {}) {
|
|
797
792
|
let result;
|
|
798
|
-
const filePath = toFilePath(
|
|
793
|
+
const filePath = toFilePath(path);
|
|
799
794
|
if (isFunction(this.resolveFS(filePath, options).promises.mkdir)) {
|
|
800
795
|
result = await this.resolveFS(filePath, options).promises.mkdir(filePath, defu4(options ?? {}, {
|
|
801
796
|
recursive: true
|
|
@@ -815,8 +810,8 @@ var VirtualFileSystem = class {
|
|
|
815
810
|
* @param options - Options for listing files, such as encoding and recursion.
|
|
816
811
|
* @returns An array of file names in the specified path.
|
|
817
812
|
*/
|
|
818
|
-
async readdir(
|
|
819
|
-
return this.resolveFS(
|
|
813
|
+
async readdir(path, options = "utf8") {
|
|
814
|
+
return this.resolveFS(path).promises.readdir(toFilePath(path), options);
|
|
820
815
|
}
|
|
821
816
|
/**
|
|
822
817
|
* Asynchronously reads a file from the virtual file system (VFS).
|
|
@@ -930,9 +925,9 @@ var VirtualFileSystem = class {
|
|
|
930
925
|
* @param options - Optional parameters for writing the runtime file.
|
|
931
926
|
* @returns A promise that resolves when the file is written.
|
|
932
927
|
*/
|
|
933
|
-
async writeBuiltinFile(id,
|
|
928
|
+
async writeBuiltinFile(id, path, contents, options = {}) {
|
|
934
929
|
const formattedId = this.formatRuntimeId(id);
|
|
935
|
-
const absolutePath = this.formatAbsoluteFilePath(toFilePath(
|
|
930
|
+
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
936
931
|
this.builtinIdMap.set(formattedId, absolutePath);
|
|
937
932
|
let data = contents;
|
|
938
933
|
if (!options.skipFormat) {
|
|
@@ -979,8 +974,8 @@ var VirtualFileSystem = class {
|
|
|
979
974
|
* @param options - Optional parameters for writing the file.
|
|
980
975
|
* @returns A promise that resolves when the file is written.
|
|
981
976
|
*/
|
|
982
|
-
async writeFileToDisk(
|
|
983
|
-
const absolutePath = this.formatAbsoluteFilePath(toFilePath(
|
|
977
|
+
async writeFileToDisk(path, contents, options = {}) {
|
|
978
|
+
const absolutePath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
984
979
|
let data = contents;
|
|
985
980
|
if (!options.skipFormat) {
|
|
986
981
|
const resolvedConfig = await resolveConfig(absolutePath);
|
|
@@ -1015,9 +1010,9 @@ var VirtualFileSystem = class {
|
|
|
1015
1010
|
* @param path - The path of the file to check.
|
|
1016
1011
|
* @returns `true` if the file exists, otherwise `false`.
|
|
1017
1012
|
*/
|
|
1018
|
-
fileExistsSync(
|
|
1019
|
-
const formattedPath = this.formatAbsoluteFilePath(toFilePath(
|
|
1020
|
-
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isFile() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isFile() || this.resolveFS(
|
|
1013
|
+
fileExistsSync(path) {
|
|
1014
|
+
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
1015
|
+
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isFile() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isFile() || this.resolveFS(path).existsSync(formattedPath) && this.resolveFS(path).lstatSync(formattedPath).isFile();
|
|
1021
1016
|
}
|
|
1022
1017
|
/**
|
|
1023
1018
|
* Checks if a directory exists in the virtual file system (VFS).
|
|
@@ -1025,9 +1020,9 @@ var VirtualFileSystem = class {
|
|
|
1025
1020
|
* @param path - The path of the directory to check.
|
|
1026
1021
|
* @returns `true` if the directory exists, otherwise `false`.
|
|
1027
1022
|
*/
|
|
1028
|
-
directoryExistsSync(
|
|
1029
|
-
const formattedPath = this.formatAbsoluteFilePath(toFilePath(
|
|
1030
|
-
return this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isDirectory() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isDirectory() || this.resolveFS(
|
|
1023
|
+
directoryExistsSync(path) {
|
|
1024
|
+
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
1025
|
+
return this.#virtualFS.existsSync(formattedPath) && this.#virtualFS.lstatSync(formattedPath).isDirectory() || this.#fs.existsSync(formattedPath) && this.#fs.lstatSync(formattedPath).isDirectory() || this.resolveFS(path).existsSync(formattedPath) && this.resolveFS(path).lstatSync(formattedPath).isDirectory();
|
|
1031
1026
|
}
|
|
1032
1027
|
/**
|
|
1033
1028
|
* Checks if a path exists in the virtual file system (VFS).
|
|
@@ -1035,9 +1030,9 @@ var VirtualFileSystem = class {
|
|
|
1035
1030
|
* @param path - The path to check.
|
|
1036
1031
|
* @returns `true` if the path exists, otherwise `false`.
|
|
1037
1032
|
*/
|
|
1038
|
-
pathExistsSync(
|
|
1039
|
-
const formattedPath = this.formatAbsoluteFilePath(toFilePath(
|
|
1040
|
-
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(
|
|
1033
|
+
pathExistsSync(path) {
|
|
1034
|
+
const formattedPath = this.formatAbsoluteFilePath(toFilePath(path));
|
|
1035
|
+
return this.isValidBuiltinId(formattedPath) || this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
|
|
1041
1036
|
}
|
|
1042
1037
|
/**
|
|
1043
1038
|
* Retrieves the status of a file in the virtual file system (VFS).
|
|
@@ -1099,12 +1094,12 @@ var VirtualFileSystem = class {
|
|
|
1099
1094
|
* @param path - The path to check.
|
|
1100
1095
|
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1101
1096
|
*/
|
|
1102
|
-
resolveTsconfigPath(
|
|
1097
|
+
resolveTsconfigPath(path) {
|
|
1103
1098
|
if (this.#context.tsconfig.options.paths) {
|
|
1104
|
-
for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) =>
|
|
1105
|
-
const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePathName(joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""),
|
|
1099
|
+
for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")))) {
|
|
1100
|
+
const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePathName(joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || this.formatAbsoluteFilePath(tsconfigPath) === this.formatAbsoluteFilePath(path));
|
|
1106
1101
|
if (resolvedPath) {
|
|
1107
|
-
return this.formatAbsoluteFilePath(resolvedPath) === this.formatAbsoluteFilePath(
|
|
1102
|
+
return this.formatAbsoluteFilePath(resolvedPath) === this.formatAbsoluteFilePath(path) ? this.formatAbsoluteFilePath(resolvedPath) : this.resolvePathName(joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), "")));
|
|
1108
1103
|
}
|
|
1109
1104
|
}
|
|
1110
1105
|
}
|
|
@@ -1118,9 +1113,9 @@ var VirtualFileSystem = class {
|
|
|
1118
1113
|
* @param path - The path to check.
|
|
1119
1114
|
* @returns The resolved file path if it exists, otherwise undefined.
|
|
1120
1115
|
*/
|
|
1121
|
-
resolveTsconfigPathPackage(
|
|
1116
|
+
resolveTsconfigPathPackage(path) {
|
|
1122
1117
|
if (this.#context.tsconfig.options.paths) {
|
|
1123
|
-
const tsconfigPathKeys = Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) =>
|
|
1118
|
+
const tsconfigPathKeys = Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")));
|
|
1124
1119
|
if (tsconfigPathKeys.length > 0 && tsconfigPathKeys[0]) {
|
|
1125
1120
|
return tsconfigPathKeys[0].replace(/\/\*$/, "");
|
|
1126
1121
|
}
|
|
@@ -1178,11 +1173,11 @@ var VirtualFileSystem = class {
|
|
|
1178
1173
|
* @param path - The file path to format.
|
|
1179
1174
|
* @returns The formatted file path.
|
|
1180
1175
|
*/
|
|
1181
|
-
formatFilePath(
|
|
1182
|
-
if (!isSetString(
|
|
1176
|
+
formatFilePath(path) {
|
|
1177
|
+
if (!isSetString(path)) {
|
|
1183
1178
|
throw new Error(`Invalid path provided. Expected a string or a valid file path.`);
|
|
1184
1179
|
}
|
|
1185
|
-
return
|
|
1180
|
+
return path.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "");
|
|
1186
1181
|
}
|
|
1187
1182
|
/**
|
|
1188
1183
|
* Converts a relative path to an absolute path based on the workspace and project root.
|
|
@@ -1190,8 +1185,8 @@ var VirtualFileSystem = class {
|
|
|
1190
1185
|
* @param path - The relative path to convert.
|
|
1191
1186
|
* @returns The absolute path.
|
|
1192
1187
|
*/
|
|
1193
|
-
formatAbsoluteFilePath = /* @__PURE__ */ __name((
|
|
1194
|
-
const formattedPath = this.formatFilePath(
|
|
1188
|
+
formatAbsoluteFilePath = /* @__PURE__ */ __name((path) => {
|
|
1189
|
+
const formattedPath = this.formatFilePath(path);
|
|
1195
1190
|
if (isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
|
|
1196
1191
|
return formattedPath;
|
|
1197
1192
|
} else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
|
|
@@ -1227,8 +1222,8 @@ var VirtualFileSystem = class {
|
|
|
1227
1222
|
return result;
|
|
1228
1223
|
}
|
|
1229
1224
|
}
|
|
1230
|
-
for (const
|
|
1231
|
-
const request = joinPaths(
|
|
1225
|
+
for (const path of this.resolveParentPaths(pathOrId, options.paths)) {
|
|
1226
|
+
const request = joinPaths(path, pathOrId);
|
|
1232
1227
|
if (options.type === "file" ? this.fileExistsSync(pathOrId) : this.pathExistsSync(pathOrId)) {
|
|
1233
1228
|
return request;
|
|
1234
1229
|
}
|
|
@@ -1245,16 +1240,16 @@ var VirtualFileSystem = class {
|
|
|
1245
1240
|
joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
|
|
1246
1241
|
];
|
|
1247
1242
|
if (this.#context.tsconfig.options.paths) {
|
|
1248
|
-
paths = this.#context.tsconfig.options.paths ? Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => request.startsWith(tsconfigPath.replaceAll("*", ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().reduce((ret,
|
|
1249
|
-
if (
|
|
1250
|
-
ret.push(joinPaths(this.#context.workspaceConfig.workspaceRoot,
|
|
1243
|
+
paths = this.#context.tsconfig.options.paths ? Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => request.startsWith(tsconfigPath.replaceAll("*", ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().reduce((ret, path) => {
|
|
1244
|
+
if (path && !ret.includes(joinPaths(this.#context.workspaceConfig.workspaceRoot, path))) {
|
|
1245
|
+
ret.push(joinPaths(this.#context.workspaceConfig.workspaceRoot, path));
|
|
1251
1246
|
}
|
|
1252
1247
|
return ret;
|
|
1253
1248
|
}, paths) : paths;
|
|
1254
1249
|
}
|
|
1255
|
-
return paths.reduce((ret,
|
|
1256
|
-
if (!ret.includes(
|
|
1257
|
-
ret.push(
|
|
1250
|
+
return paths.reduce((ret, path) => {
|
|
1251
|
+
if (!ret.includes(path)) {
|
|
1252
|
+
ret.push(path);
|
|
1258
1253
|
}
|
|
1259
1254
|
return ret;
|
|
1260
1255
|
}, current.filter(Boolean).map((p) => this.formatAbsoluteFilePath(toFilePath(p))));
|
|
@@ -1295,8 +1290,8 @@ var VirtualFileSystem = class {
|
|
|
1295
1290
|
*
|
|
1296
1291
|
* @param path - The path to clear the resolver cache for.
|
|
1297
1292
|
*/
|
|
1298
|
-
clearResolverCache(
|
|
1299
|
-
this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(
|
|
1293
|
+
clearResolverCache(path) {
|
|
1294
|
+
this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
|
|
1300
1295
|
}
|
|
1301
1296
|
};
|
|
1302
1297
|
var FILE_PREFIX = "file://";
|
|
@@ -1432,12 +1427,12 @@ function patchFS(originalFS, vfs) {
|
|
|
1432
1427
|
}
|
|
1433
1428
|
__name(patchFS, "patchFS");
|
|
1434
1429
|
function checkVariants(request, vfs, parentPath) {
|
|
1435
|
-
const
|
|
1436
|
-
let file = checkExtensions(
|
|
1430
|
+
const path = parentPath ? joinPaths(parentPath, request) : request;
|
|
1431
|
+
let file = checkExtensions(path, vfs);
|
|
1437
1432
|
if (file) {
|
|
1438
1433
|
return file;
|
|
1439
1434
|
}
|
|
1440
|
-
file = checkIndex(
|
|
1435
|
+
file = checkIndex(path, vfs);
|
|
1441
1436
|
if (file) {
|
|
1442
1437
|
return file;
|
|
1443
1438
|
}
|
|
@@ -2274,381 +2269,6 @@ var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext
|
|
|
2274
2269
|
}
|
|
2275
2270
|
}
|
|
2276
2271
|
};
|
|
2277
|
-
async function installPackage(context, packageName, dev = false) {
|
|
2278
|
-
const isListed = await isPackageListed(packageName, {
|
|
2279
|
-
cwd: context.config.projectRoot
|
|
2280
|
-
});
|
|
2281
|
-
if (!isListed) {
|
|
2282
|
-
if (context.config.skipInstalls !== true && !process.env.POWERLINES_LOCAL) {
|
|
2283
|
-
context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
2284
|
-
const result = await install(packageName, {
|
|
2285
|
-
cwd: context.config.projectRoot,
|
|
2286
|
-
dev
|
|
2287
|
-
});
|
|
2288
|
-
if (isNumber(result.exitCode) && result.exitCode > 0) {
|
|
2289
|
-
context.log(LogLevelLabel.ERROR, result.stderr);
|
|
2290
|
-
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
2291
|
-
}
|
|
2292
|
-
} else {
|
|
2293
|
-
context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
|
|
2294
|
-
}
|
|
2295
|
-
} else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
|
|
2296
|
-
const isMatching = await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot);
|
|
2297
|
-
if (!isMatching) {
|
|
2298
|
-
const packageListing = await getPackageListing(getPackageName(packageName), {
|
|
2299
|
-
cwd: context.config.projectRoot
|
|
2300
|
-
});
|
|
2301
|
-
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) {
|
|
2302
|
-
context.log(LogLevelLabel.WARN, `The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
__name(installPackage, "installPackage");
|
|
2308
|
-
async function installPackages(context, packages) {
|
|
2309
|
-
return Promise.all(packages.map(async (pkg) => installPackage(context, pkg.name, pkg.dev)));
|
|
2310
|
-
}
|
|
2311
|
-
__name(installPackages, "installPackages");
|
|
2312
|
-
|
|
2313
|
-
// ../powerlines/src/internal/helpers/eslint.ts
|
|
2314
|
-
var MessageSeverity;
|
|
2315
|
-
(function(MessageSeverity2) {
|
|
2316
|
-
MessageSeverity2[MessageSeverity2["Warning"] = 1] = "Warning";
|
|
2317
|
-
MessageSeverity2[MessageSeverity2["Error"] = 2] = "Error";
|
|
2318
|
-
})(MessageSeverity || (MessageSeverity = {}));
|
|
2319
|
-
function pluginCount(messages) {
|
|
2320
|
-
let nextPluginWarningCount = 0;
|
|
2321
|
-
let nextPluginErrorCount = 0;
|
|
2322
|
-
for (let i = 0; i < messages.length; i++) {
|
|
2323
|
-
const { severity, ruleId } = messages[i];
|
|
2324
|
-
if (ruleId?.includes("powerlines")) {
|
|
2325
|
-
if (severity === 1) {
|
|
2326
|
-
nextPluginWarningCount += 1;
|
|
2327
|
-
} else {
|
|
2328
|
-
nextPluginErrorCount += 1;
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
return {
|
|
2333
|
-
nextPluginErrorCount,
|
|
2334
|
-
nextPluginWarningCount
|
|
2335
|
-
};
|
|
2336
|
-
}
|
|
2337
|
-
__name(pluginCount, "pluginCount");
|
|
2338
|
-
function formatMessage(dir, messages, filePath) {
|
|
2339
|
-
let fileName = path.posix.normalize(path.relative(dir, filePath).replace(/\\/g, "/"));
|
|
2340
|
-
if (!fileName.startsWith(".")) {
|
|
2341
|
-
fileName = `./${fileName}`;
|
|
2342
|
-
}
|
|
2343
|
-
let output = `
|
|
2344
|
-
${fileName}`;
|
|
2345
|
-
for (let i = 0; i < messages.length; i++) {
|
|
2346
|
-
const { message, severity, line, column, ruleId } = messages[i];
|
|
2347
|
-
output += "\n";
|
|
2348
|
-
if (line && column) {
|
|
2349
|
-
output = `${output + line.toString()}:${column.toString()} `;
|
|
2350
|
-
}
|
|
2351
|
-
if (severity === 1) {
|
|
2352
|
-
output += `Warning: `;
|
|
2353
|
-
} else {
|
|
2354
|
-
output += `Error: `;
|
|
2355
|
-
}
|
|
2356
|
-
output += message;
|
|
2357
|
-
if (ruleId) {
|
|
2358
|
-
output += ` ${ruleId}`;
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
return output;
|
|
2362
|
-
}
|
|
2363
|
-
__name(formatMessage, "formatMessage");
|
|
2364
|
-
async function formatResults(baseDir, results, format3) {
|
|
2365
|
-
let totalPluginErrorCount = 0;
|
|
2366
|
-
let totalPluginWarningCount = 0;
|
|
2367
|
-
const resultsWithMessages = results.filter(({ messages }) => messages?.length);
|
|
2368
|
-
resultsWithMessages.forEach(({ messages }) => {
|
|
2369
|
-
const res = pluginCount(messages);
|
|
2370
|
-
totalPluginErrorCount += res.nextPluginErrorCount;
|
|
2371
|
-
totalPluginWarningCount += res.nextPluginWarningCount;
|
|
2372
|
-
});
|
|
2373
|
-
const output = format3 ? await format3(resultsWithMessages) : resultsWithMessages.map(({ messages, filePath }) => formatMessage(baseDir, messages, filePath)).join("\n");
|
|
2374
|
-
return {
|
|
2375
|
-
output,
|
|
2376
|
-
outputWithMessages: resultsWithMessages.length > 0 ? `${output}
|
|
2377
|
-
|
|
2378
|
-
Info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/app/api-reference/config/eslint#disabling-rules` : "",
|
|
2379
|
-
totalPluginErrorCount,
|
|
2380
|
-
totalPluginWarningCount
|
|
2381
|
-
};
|
|
2382
|
-
}
|
|
2383
|
-
__name(formatResults, "formatResults");
|
|
2384
|
-
async function writeDefaultEslintConfig(log, context, type = "recommended") {
|
|
2385
|
-
const eslintConfigFile = joinPaths(context.workspaceConfig.workspaceRoot, "eslint.config.js");
|
|
2386
|
-
const eslintConfig = `
|
|
2387
|
-
import { getConfig } from "eslint-config-powerlines";
|
|
2388
|
-
|
|
2389
|
-
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
2390
|
-
|
|
2391
|
-
export default getConfig({
|
|
2392
|
-
repositoryName: "${context.workspaceConfig.name || context.config.name || "powerlines"}",
|
|
2393
|
-
"powerlines": "${type}",
|
|
2394
|
-
});
|
|
2395
|
-
`;
|
|
2396
|
-
log(LogLevelLabel.INFO, `Writing a default ESLint config file to ${eslintConfigFile}`);
|
|
2397
|
-
return writeFile(log, eslintConfigFile, eslintConfig);
|
|
2398
|
-
}
|
|
2399
|
-
__name(writeDefaultEslintConfig, "writeDefaultEslintConfig");
|
|
2400
|
-
var VALID_SEVERITY = [
|
|
2401
|
-
"off",
|
|
2402
|
-
"warn",
|
|
2403
|
-
"error"
|
|
2404
|
-
];
|
|
2405
|
-
function isValidSeverity(severity) {
|
|
2406
|
-
return VALID_SEVERITY.includes(severity);
|
|
2407
|
-
}
|
|
2408
|
-
__name(isValidSeverity, "isValidSeverity");
|
|
2409
|
-
async function writeOutputFile(log, outputFile, outputData) {
|
|
2410
|
-
const filePath = path.resolve(process.cwd(), outputFile);
|
|
2411
|
-
if (isDirectory(filePath)) {
|
|
2412
|
-
log(LogLevelLabel.ERROR, `Cannot write to output file path, it is a directory: ${filePath}`);
|
|
2413
|
-
} else {
|
|
2414
|
-
try {
|
|
2415
|
-
await writeFile(log, filePath, outputData);
|
|
2416
|
-
log(LogLevelLabel.INFO, `The output file has been created: ${filePath}`);
|
|
2417
|
-
} catch (err) {
|
|
2418
|
-
log(LogLevelLabel.ERROR, `There was a problem writing the output file: ${filePath}`);
|
|
2419
|
-
console.error(err);
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
__name(writeOutputFile, "writeOutputFile");
|
|
2424
|
-
async function hasEslintConfiguration(eslintFile, packageJsonConfig) {
|
|
2425
|
-
const configObject = {
|
|
2426
|
-
exists: false,
|
|
2427
|
-
emptyEslint: false,
|
|
2428
|
-
emptyPkgJsonConfig: false
|
|
2429
|
-
};
|
|
2430
|
-
if (eslintFile) {
|
|
2431
|
-
const content = await readFile(eslintFile).then((txt) => txt.trim().replace(/\n/g, ""), () => null);
|
|
2432
|
-
if (content === "" || content === "{}" || content === "---" || content === "module.exports = {}") {
|
|
2433
|
-
configObject.emptyEslint = true;
|
|
2434
|
-
} else {
|
|
2435
|
-
configObject.exists = true;
|
|
2436
|
-
}
|
|
2437
|
-
} else if (packageJsonConfig?.eslintConfig) {
|
|
2438
|
-
if (Object.keys(packageJsonConfig.eslintConfig).length) {
|
|
2439
|
-
configObject.exists = true;
|
|
2440
|
-
} else {
|
|
2441
|
-
configObject.emptyPkgJsonConfig = true;
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
return configObject;
|
|
2445
|
-
}
|
|
2446
|
-
__name(hasEslintConfiguration, "hasEslintConfiguration");
|
|
2447
|
-
var lint = /* @__PURE__ */ __name(async (log, context, eslintConfigPath, { lintDuringBuild = false, eslintOptions = null, reportErrorsOnly = false, maxWarnings = -1, formatter = null, outputFile = null }) => {
|
|
2448
|
-
try {
|
|
2449
|
-
await installPackages(context, [
|
|
2450
|
-
{
|
|
2451
|
-
name: "eslint",
|
|
2452
|
-
dev: true
|
|
2453
|
-
},
|
|
2454
|
-
{
|
|
2455
|
-
name: "eslint-config-powerlines",
|
|
2456
|
-
dev: true
|
|
2457
|
-
}
|
|
2458
|
-
]);
|
|
2459
|
-
const isInstalled = isPackageExists("eslint", {
|
|
2460
|
-
paths: [
|
|
2461
|
-
context.workspaceConfig.workspaceRoot,
|
|
2462
|
-
context.config.projectRoot
|
|
2463
|
-
]
|
|
2464
|
-
});
|
|
2465
|
-
if (!isInstalled) {
|
|
2466
|
-
log(LogLevelLabel.ERROR, `ESLint must be installed${lintDuringBuild ? " in order to run during builds:" : ":"} npm install --save-dev eslint`);
|
|
2467
|
-
return null;
|
|
2468
|
-
}
|
|
2469
|
-
const module = await context.resolver.import(context.resolver.esmResolve("eslint"));
|
|
2470
|
-
const useFlatConfig = eslintConfigPath ? findFileName(eslintConfigPath).startsWith("eslint.config.") : false;
|
|
2471
|
-
let ESLint;
|
|
2472
|
-
if ("loadESLint" in module) {
|
|
2473
|
-
ESLint = await module.loadESLint({
|
|
2474
|
-
useFlatConfig
|
|
2475
|
-
});
|
|
2476
|
-
}
|
|
2477
|
-
const eslintVersion = parseVersion(ESLint?.version);
|
|
2478
|
-
if (!eslintVersion || eslintVersion.compare("8.57.0") < 0) {
|
|
2479
|
-
return `Error - Your project has an older version of ESLint installed${eslintVersion ? ` (${eslintVersion.major}.${eslintVersion.minor}.${eslintVersion.patch})` : ""}. Please upgrade to ESLint version 8.57.0 or above`;
|
|
2480
|
-
}
|
|
2481
|
-
const options = {
|
|
2482
|
-
useEslintrc: true,
|
|
2483
|
-
baseConfig: {},
|
|
2484
|
-
errorOnUnmatchedPattern: false,
|
|
2485
|
-
extensions: [
|
|
2486
|
-
".js",
|
|
2487
|
-
".jsx",
|
|
2488
|
-
".ts",
|
|
2489
|
-
".tsx"
|
|
2490
|
-
],
|
|
2491
|
-
cache: true,
|
|
2492
|
-
...eslintOptions
|
|
2493
|
-
};
|
|
2494
|
-
if (eslintVersion?.compare("9.0.0") && useFlatConfig) {
|
|
2495
|
-
for (const option of [
|
|
2496
|
-
"useEslintrc",
|
|
2497
|
-
"extensions",
|
|
2498
|
-
"ignorePath",
|
|
2499
|
-
"reportUnusedDisableDirectives",
|
|
2500
|
-
"resolvePluginsRelativeTo",
|
|
2501
|
-
"rulePaths",
|
|
2502
|
-
"inlineConfig",
|
|
2503
|
-
"maxWarnings"
|
|
2504
|
-
]) {
|
|
2505
|
-
if (option in options) {
|
|
2506
|
-
delete options[option];
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
let eslint2 = new ESLint(options);
|
|
2511
|
-
let stormStackEslintPluginIsEnabled = false;
|
|
2512
|
-
const stormStackRulesEnabled = /* @__PURE__ */ new Map();
|
|
2513
|
-
for (const configFile of [
|
|
2514
|
-
eslintConfigPath,
|
|
2515
|
-
joinPaths(context.config.projectRoot, "package.json")
|
|
2516
|
-
]) {
|
|
2517
|
-
if (!configFile) continue;
|
|
2518
|
-
const completeConfig = await eslint2.calculateConfigForFile(configFile);
|
|
2519
|
-
if (!completeConfig) continue;
|
|
2520
|
-
const plugins2 = completeConfig.plugins;
|
|
2521
|
-
const hasStormStackPlugin = (
|
|
2522
|
-
// in ESLint < 9, `plugins` value is string[]
|
|
2523
|
-
Array.isArray(plugins2) ? plugins2.includes("powerlines") : "powerlines" in plugins2
|
|
2524
|
-
);
|
|
2525
|
-
if (hasStormStackPlugin) {
|
|
2526
|
-
stormStackEslintPluginIsEnabled = true;
|
|
2527
|
-
for (const [name, [severity]] of Object.entries(completeConfig.rules)) {
|
|
2528
|
-
if (!name.startsWith("powerlines/")) {
|
|
2529
|
-
continue;
|
|
2530
|
-
}
|
|
2531
|
-
if (typeof severity === "number" && severity >= 0 && severity < VALID_SEVERITY.length) {
|
|
2532
|
-
stormStackRulesEnabled.set(name, VALID_SEVERITY[severity]);
|
|
2533
|
-
} else if (typeof severity === "string" && isValidSeverity(severity)) {
|
|
2534
|
-
stormStackRulesEnabled.set(name, severity);
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
break;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
if (stormStackEslintPluginIsEnabled) {
|
|
2541
|
-
eslint2 = new ESLint(options);
|
|
2542
|
-
} else {
|
|
2543
|
-
log(LogLevelLabel.WARN, "The Powerlines plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/app/api-reference/config/eslint#migrating-existing-config");
|
|
2544
|
-
}
|
|
2545
|
-
const lintStart = process.hrtime();
|
|
2546
|
-
let results = await eslint2.lintFiles(context.tsconfig.fileNames.filter((fileName) => !fileName.includes(context.artifactsPath) && !fileName.includes("node_modules")));
|
|
2547
|
-
let selectedFormatter = null;
|
|
2548
|
-
if (options.fix) {
|
|
2549
|
-
await ESLint.outputFixes(results);
|
|
2550
|
-
}
|
|
2551
|
-
if (reportErrorsOnly) {
|
|
2552
|
-
results = ESLint.getErrorResults(results);
|
|
2553
|
-
}
|
|
2554
|
-
if (formatter) {
|
|
2555
|
-
selectedFormatter = await eslint2.loadFormatter(formatter);
|
|
2556
|
-
}
|
|
2557
|
-
const formattedResult = await formatResults(context.config.projectRoot, results, selectedFormatter?.format?.bind(selectedFormatter));
|
|
2558
|
-
const lintEnd = process.hrtime(lintStart);
|
|
2559
|
-
const totalWarnings = results.reduce((sum, file) => sum + file.warningCount, 0);
|
|
2560
|
-
if (outputFile) {
|
|
2561
|
-
await writeOutputFile(log, outputFile, formattedResult.output);
|
|
2562
|
-
}
|
|
2563
|
-
return {
|
|
2564
|
-
output: formattedResult.outputWithMessages,
|
|
2565
|
-
isError: ESLint.getErrorResults(results)?.length > 0 || maxWarnings >= 0 && totalWarnings > maxWarnings,
|
|
2566
|
-
eventInfo: {
|
|
2567
|
-
durationInSeconds: lintEnd[0],
|
|
2568
|
-
eslintVersion: eslintVersion.version,
|
|
2569
|
-
lintedFilesCount: results.length,
|
|
2570
|
-
lintFix: !!options.fix,
|
|
2571
|
-
eslintPluginErrorsCount: formattedResult.totalPluginErrorCount,
|
|
2572
|
-
eslintPluginWarningsCount: formattedResult.totalPluginWarningCount,
|
|
2573
|
-
stormStackRulesEnabled: Object.fromEntries(stormStackRulesEnabled)
|
|
2574
|
-
}
|
|
2575
|
-
};
|
|
2576
|
-
} catch (err) {
|
|
2577
|
-
if (lintDuringBuild) {
|
|
2578
|
-
log(LogLevelLabel.ERROR, `ESLint: ${isError(err) && err.message ? err.message.replace(/\n/g, " ") : String(err)}`);
|
|
2579
|
-
return null;
|
|
2580
|
-
} else {
|
|
2581
|
-
throw err;
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
}, "lint");
|
|
2585
|
-
async function eslint(context, lintDuringBuild = false, opts = {}) {
|
|
2586
|
-
const { eslintOptions = null, reportErrorsOnly = false, maxWarnings = -1, formatter = null, outputFile = null, type = "recommended" } = opts;
|
|
2587
|
-
const eslintFile = getParentPath([
|
|
2588
|
-
// eslint v9
|
|
2589
|
-
"eslint.config.js",
|
|
2590
|
-
"eslint.config.mjs",
|
|
2591
|
-
"eslint.config.cjs",
|
|
2592
|
-
// TS extensions require to install a separate package `jiti`.
|
|
2593
|
-
// https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files
|
|
2594
|
-
"eslint.config.ts",
|
|
2595
|
-
"eslint.config.mts",
|
|
2596
|
-
"eslint.config.cts",
|
|
2597
|
-
// eslint <= v8
|
|
2598
|
-
".eslintrc.js",
|
|
2599
|
-
".eslintrc.cjs",
|
|
2600
|
-
".eslintrc.yaml",
|
|
2601
|
-
".eslintrc.yml",
|
|
2602
|
-
".eslintrc.json",
|
|
2603
|
-
".eslintrc"
|
|
2604
|
-
], context.config.projectRoot) ?? null;
|
|
2605
|
-
const config = await hasEslintConfiguration(eslintFile, context.packageJson);
|
|
2606
|
-
if (config.exists) {
|
|
2607
|
-
return lint(context.log, context, eslintFile, {
|
|
2608
|
-
lintDuringBuild,
|
|
2609
|
-
eslintOptions,
|
|
2610
|
-
reportErrorsOnly,
|
|
2611
|
-
maxWarnings,
|
|
2612
|
-
formatter,
|
|
2613
|
-
outputFile
|
|
2614
|
-
});
|
|
2615
|
-
}
|
|
2616
|
-
if (lintDuringBuild) {
|
|
2617
|
-
if (config.emptyPkgJsonConfig || config.emptyEslint) {
|
|
2618
|
-
context.log(LogLevelLabel.WARN, `No ESLint configuration detected. Run "storm lint" to begin setup`);
|
|
2619
|
-
}
|
|
2620
|
-
return null;
|
|
2621
|
-
} else {
|
|
2622
|
-
const isEslintInstalled = isPackageExists("eslint", {
|
|
2623
|
-
paths: [
|
|
2624
|
-
context.workspaceConfig.workspaceRoot,
|
|
2625
|
-
context.config.projectRoot
|
|
2626
|
-
]
|
|
2627
|
-
});
|
|
2628
|
-
const isEslintPluginInstalled = isPackageExists("eslint-config-powerlines", {
|
|
2629
|
-
paths: [
|
|
2630
|
-
context.workspaceConfig.workspaceRoot,
|
|
2631
|
-
context.config.projectRoot
|
|
2632
|
-
]
|
|
2633
|
-
});
|
|
2634
|
-
if (!isEslintInstalled || !isEslintPluginInstalled) {
|
|
2635
|
-
await installPackages(context, [
|
|
2636
|
-
{
|
|
2637
|
-
name: "eslint",
|
|
2638
|
-
dev: true
|
|
2639
|
-
},
|
|
2640
|
-
{
|
|
2641
|
-
name: "eslint-config-powerlines",
|
|
2642
|
-
dev: true
|
|
2643
|
-
}
|
|
2644
|
-
]);
|
|
2645
|
-
}
|
|
2646
|
-
await writeDefaultEslintConfig(context.log, context, type);
|
|
2647
|
-
}
|
|
2648
|
-
context.log(LogLevelLabel.SUCCESS, `ESLint has successfully been configured. Run "storm lint" again to view warnings and errors.`);
|
|
2649
|
-
return null;
|
|
2650
|
-
}
|
|
2651
|
-
__name(eslint, "eslint");
|
|
2652
2272
|
function getString(code) {
|
|
2653
2273
|
if (!code) {
|
|
2654
2274
|
return "";
|
|
@@ -2899,13 +2519,47 @@ ${builtinModules}`.replace(
|
|
|
2899
2519
|
await context.fs.writeFileToDisk(sourceFile.id, getString(sourceFile.code));
|
|
2900
2520
|
}
|
|
2901
2521
|
__name(generateTypes, "generateTypes");
|
|
2522
|
+
async function installPackage(context, packageName, dev = false) {
|
|
2523
|
+
if (!await isPackageListed(getPackageName(packageName), {
|
|
2524
|
+
cwd: context.config.projectRoot
|
|
2525
|
+
})) {
|
|
2526
|
+
if (context.config.skipInstalls !== true && !process.env.POWERLINES_LOCAL) {
|
|
2527
|
+
context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
2528
|
+
const result = await install(packageName, {
|
|
2529
|
+
cwd: context.config.projectRoot,
|
|
2530
|
+
dev
|
|
2531
|
+
});
|
|
2532
|
+
if (isNumber(result.exitCode) && result.exitCode > 0) {
|
|
2533
|
+
context.log(LogLevelLabel.ERROR, result.stderr);
|
|
2534
|
+
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
2535
|
+
}
|
|
2536
|
+
} else {
|
|
2537
|
+
context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
|
|
2538
|
+
}
|
|
2539
|
+
} else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
|
|
2540
|
+
const isMatching = await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot);
|
|
2541
|
+
if (!isMatching) {
|
|
2542
|
+
const packageListing = await getPackageListing(getPackageName(packageName), {
|
|
2543
|
+
cwd: context.config.projectRoot
|
|
2544
|
+
});
|
|
2545
|
+
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) {
|
|
2546
|
+
context.log(LogLevelLabel.WARN, `The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
__name(installPackage, "installPackage");
|
|
2552
|
+
|
|
2553
|
+
// ../powerlines/src/internal/helpers/install-dependencies.ts
|
|
2902
2554
|
async function installDependencies(context) {
|
|
2903
2555
|
context.log(LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
|
|
2904
2556
|
context.dependencies ??= {};
|
|
2905
|
-
context.
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2557
|
+
context.log(LogLevelLabel.TRACE, `The following packages are required:
|
|
2558
|
+
Dependencies:
|
|
2559
|
+
${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}
|
|
2560
|
+
|
|
2561
|
+
DevDependencies:
|
|
2562
|
+
${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
|
|
2909
2563
|
await Promise.all([
|
|
2910
2564
|
Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, false))),
|
|
2911
2565
|
Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, true)))
|
|
@@ -2949,22 +2603,22 @@ async function resolveTsconfigChanges(context) {
|
|
|
2949
2603
|
tsconfigJson.compilerOptions.lib ??= [];
|
|
2950
2604
|
tsconfigJson.compilerOptions.lib.push("esnext");
|
|
2951
2605
|
}
|
|
2952
|
-
if (tsconfig.options.module !==
|
|
2606
|
+
if (tsconfig.options.module !== ts2.ModuleKind.ESNext) {
|
|
2953
2607
|
tsconfigJson.compilerOptions.module = "ESNext";
|
|
2954
2608
|
}
|
|
2955
2609
|
if (!tsconfig.options.target || ![
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2610
|
+
ts2.ScriptTarget.ESNext,
|
|
2611
|
+
ts2.ScriptTarget.ES2024,
|
|
2612
|
+
ts2.ScriptTarget.ES2023,
|
|
2613
|
+
ts2.ScriptTarget.ES2022,
|
|
2614
|
+
ts2.ScriptTarget.ES2021
|
|
2961
2615
|
].includes(tsconfig.options.target)) {
|
|
2962
2616
|
tsconfigJson.compilerOptions.target = "ESNext";
|
|
2963
2617
|
}
|
|
2964
|
-
if (tsconfig.options.moduleResolution !==
|
|
2618
|
+
if (tsconfig.options.moduleResolution !== ts2.ModuleResolutionKind.Bundler) {
|
|
2965
2619
|
tsconfigJson.compilerOptions.moduleResolution = "Bundler";
|
|
2966
2620
|
}
|
|
2967
|
-
if (tsconfig.options.moduleDetection !==
|
|
2621
|
+
if (tsconfig.options.moduleDetection !== ts2.ModuleDetectionKind.Force) {
|
|
2968
2622
|
tsconfigJson.compilerOptions.moduleDetection = "force";
|
|
2969
2623
|
}
|
|
2970
2624
|
if (tsconfig.options.allowSyntheticDefaultImports !== true) {
|
|
@@ -2998,7 +2652,7 @@ async function resolveTsconfigChanges(context) {
|
|
|
2998
2652
|
tsconfigJson.compilerOptions.declaration = true;
|
|
2999
2653
|
}
|
|
3000
2654
|
if (context.environment.consumer === "client") {
|
|
3001
|
-
if (tsconfig.options.jsx !==
|
|
2655
|
+
if (tsconfig.options.jsx !== ts2.JsxEmit.ReactJSX) {
|
|
3002
2656
|
tsconfigJson.compilerOptions.jsx = "react-jsx";
|
|
3003
2657
|
}
|
|
3004
2658
|
if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom")) {
|
|
@@ -3084,127 +2738,6 @@ async function resolveTsconfig(context) {
|
|
|
3084
2738
|
context.tsconfig.tsconfigJson.compilerOptions.strict = false;
|
|
3085
2739
|
}
|
|
3086
2740
|
__name(resolveTsconfig, "resolveTsconfig");
|
|
3087
|
-
function getDefaultCompilerOptions() {
|
|
3088
|
-
return {
|
|
3089
|
-
...ts3.getDefaultCompilerOptions(),
|
|
3090
|
-
jsx: ts3.JsxEmit.React,
|
|
3091
|
-
strict: true,
|
|
3092
|
-
esModuleInterop: true,
|
|
3093
|
-
module: ts3.ModuleKind.ESNext,
|
|
3094
|
-
suppressOutputPathCheck: true,
|
|
3095
|
-
skipLibCheck: true,
|
|
3096
|
-
skipDefaultLibCheck: true,
|
|
3097
|
-
moduleResolution: ts3.ModuleResolutionKind.Node10
|
|
3098
|
-
};
|
|
3099
|
-
}
|
|
3100
|
-
__name(getDefaultCompilerOptions, "getDefaultCompilerOptions");
|
|
3101
|
-
async function createVirtualProgram(rootNames, context, compilerOptions = {}) {
|
|
3102
|
-
const options = defu4(compilerOptions, getDefaultCompilerOptions());
|
|
3103
|
-
const host = {
|
|
3104
|
-
name: "storm-vfs",
|
|
3105
|
-
root: context.workspaceConfig.workspaceRoot,
|
|
3106
|
-
...ts3.sys,
|
|
3107
|
-
realpath: /* @__PURE__ */ __name((path2) => {
|
|
3108
|
-
if (context.fs.existsSync(path2)) {
|
|
3109
|
-
return context.fs.resolvePath(path2);
|
|
3110
|
-
}
|
|
3111
|
-
return ts3.sys.realpath?.(path2) ?? path2;
|
|
3112
|
-
}, "realpath"),
|
|
3113
|
-
getCurrentDirectory() {
|
|
3114
|
-
return context.workspaceConfig.workspaceRoot;
|
|
3115
|
-
},
|
|
3116
|
-
getCanonicalFileName(fileName) {
|
|
3117
|
-
return fileName;
|
|
3118
|
-
},
|
|
3119
|
-
getDefaultLibFileName(_options) {
|
|
3120
|
-
return ts3.getDefaultLibFileName(options);
|
|
3121
|
-
},
|
|
3122
|
-
getDefaultLibLocation() {
|
|
3123
|
-
return "/";
|
|
3124
|
-
},
|
|
3125
|
-
getNewLine() {
|
|
3126
|
-
return "\n";
|
|
3127
|
-
},
|
|
3128
|
-
useCaseSensitiveFileNames() {
|
|
3129
|
-
return true;
|
|
3130
|
-
},
|
|
3131
|
-
fileExists(fileName) {
|
|
3132
|
-
return context.fs.existsSync(fileName);
|
|
3133
|
-
},
|
|
3134
|
-
readFile(fileName) {
|
|
3135
|
-
if (context.fs.existsSync(fileName)) {
|
|
3136
|
-
return context.fs.readFileSync(fileName);
|
|
3137
|
-
}
|
|
3138
|
-
return void 0;
|
|
3139
|
-
},
|
|
3140
|
-
readDirectory: /* @__PURE__ */ __name((path2, extensions = [], exclude = [], include = []) => {
|
|
3141
|
-
let results = [];
|
|
3142
|
-
if (context.fs.existsSync(path2)) {
|
|
3143
|
-
results = context.fs.readdirSync(path2, {
|
|
3144
|
-
encoding: "utf8",
|
|
3145
|
-
recursive: true
|
|
3146
|
-
});
|
|
3147
|
-
if (extensions.length > 0) {
|
|
3148
|
-
results = results.filter((file) => extensions.some((ext) => file.endsWith(ext.startsWith(".") ? ext : `.${ext}`)));
|
|
3149
|
-
}
|
|
3150
|
-
if (exclude.length > 0) {
|
|
3151
|
-
results = results.filter((file) => !exclude.some((pattern) => minimatch(file, pattern)));
|
|
3152
|
-
}
|
|
3153
|
-
if (include.length > 0) {
|
|
3154
|
-
results = results.filter((file) => include.some((pattern) => minimatch(file, pattern)));
|
|
3155
|
-
}
|
|
3156
|
-
}
|
|
3157
|
-
return results;
|
|
3158
|
-
}, "readDirectory"),
|
|
3159
|
-
writeFile(fileName, data) {
|
|
3160
|
-
context.fs.writeFileSync(fileName, data);
|
|
3161
|
-
},
|
|
3162
|
-
resolvePath: /* @__PURE__ */ __name((fileName) => {
|
|
3163
|
-
if (context.fs.existsSync(fileName)) {
|
|
3164
|
-
return context.fs.resolvePath(fileName);
|
|
3165
|
-
}
|
|
3166
|
-
return ts3.sys.resolvePath(fileName);
|
|
3167
|
-
}, "resolvePath"),
|
|
3168
|
-
getSourceFile(fileName, languageVersionOrOptions, _, shouldCreateNewSourceFile) {
|
|
3169
|
-
if (context.fs.existsSync(fileName)) {
|
|
3170
|
-
return ts3.createSourceFile(fileName, context.fs.readFileSync(fileName), languageVersionOrOptions ?? compilerOptions.target ?? getDefaultCompilerOptions().target, false);
|
|
3171
|
-
} else if (shouldCreateNewSourceFile) {
|
|
3172
|
-
const sourceFile = ts3.createSourceFile(fileName, "", languageVersionOrOptions ?? compilerOptions.target ?? getDefaultCompilerOptions().target, false);
|
|
3173
|
-
context.fs.writeFileSync(fileName, sourceFile.text);
|
|
3174
|
-
return sourceFile;
|
|
3175
|
-
}
|
|
3176
|
-
return void 0;
|
|
3177
|
-
}
|
|
3178
|
-
};
|
|
3179
|
-
return ts3.createProgram(rootNames, options, host);
|
|
3180
|
-
}
|
|
3181
|
-
__name(createVirtualProgram, "createVirtualProgram");
|
|
3182
|
-
|
|
3183
|
-
// ../powerlines/src/internal/helpers/tsc.ts
|
|
3184
|
-
async function typeCheck(context, sources) {
|
|
3185
|
-
if (sources) {
|
|
3186
|
-
await Promise.all(sources.entries().map(async ([path2, content]) => context.fs.writeFile(path2, content)));
|
|
3187
|
-
}
|
|
3188
|
-
const program = await createVirtualProgram(sources ? Array.from(sources.keys()) : [], context, {
|
|
3189
|
-
noEmit: true,
|
|
3190
|
-
lib: [
|
|
3191
|
-
"lib.esnext.d.ts"
|
|
3192
|
-
],
|
|
3193
|
-
types: []
|
|
3194
|
-
});
|
|
3195
|
-
const emitResult = program.emit();
|
|
3196
|
-
const allDiagnostics = ts3.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
3197
|
-
allDiagnostics.forEach((diagnostic) => {
|
|
3198
|
-
if (diagnostic.file) {
|
|
3199
|
-
const { line, character } = ts3.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
3200
|
-
const message = ts3.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
3201
|
-
context.log(LogLevelLabel.ERROR, `${diagnostic.file.fileName}:${line + 1}:${character + 1} : ${message}`);
|
|
3202
|
-
} else {
|
|
3203
|
-
context.log(LogLevelLabel.ERROR, ts3.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
3204
|
-
}
|
|
3205
|
-
});
|
|
3206
|
-
}
|
|
3207
|
-
__name(typeCheck, "typeCheck");
|
|
3208
2741
|
|
|
3209
2742
|
// ../powerlines/src/internal/api.ts
|
|
3210
2743
|
var PowerlinesAPI = class _PowerlinesAPI {
|
|
@@ -3378,11 +2911,7 @@ ${formatLogMessage(context.config)}`);
|
|
|
3378
2911
|
await this.prepare(inlineConfig);
|
|
3379
2912
|
await this.#executeEnvironments(async (context) => {
|
|
3380
2913
|
if (context.config.lint !== false) {
|
|
3381
|
-
await this.
|
|
3382
|
-
await typeCheck(context);
|
|
3383
|
-
await eslint(context, true, context.config.lint.eslint);
|
|
3384
|
-
await this.callNormalHook(context, "lint");
|
|
3385
|
-
await this.callPostHook(context, "lint");
|
|
2914
|
+
await this.callHook(context, "lint");
|
|
3386
2915
|
}
|
|
3387
2916
|
});
|
|
3388
2917
|
this.context.log(LogLevelLabel.TRACE, "Powerlines linting completed");
|
|
@@ -3732,9 +3261,9 @@ var DEFAULT_ESBUILD_CONFIG = {
|
|
|
3732
3261
|
function extractESBuildConfig(context) {
|
|
3733
3262
|
return defu4({
|
|
3734
3263
|
alias: context.fs.builtinIdMap.keys().reduce((ret, id) => {
|
|
3735
|
-
const
|
|
3736
|
-
if (
|
|
3737
|
-
ret[id] =
|
|
3264
|
+
const path = context.fs.builtinIdMap.get(id);
|
|
3265
|
+
if (path) {
|
|
3266
|
+
ret[id] = path;
|
|
3738
3267
|
}
|
|
3739
3268
|
return ret;
|
|
3740
3269
|
}, {})
|
|
@@ -3776,9 +3305,9 @@ function extractViteConfig(context) {
|
|
|
3776
3305
|
return defu4({
|
|
3777
3306
|
resolve: {
|
|
3778
3307
|
alias: context.fs.builtinIdMap.keys().reduce((ret, id) => {
|
|
3779
|
-
const
|
|
3780
|
-
if (
|
|
3781
|
-
ret[id] =
|
|
3308
|
+
const path = context.fs.builtinIdMap.get(id);
|
|
3309
|
+
if (path) {
|
|
3310
|
+
ret[id] = path;
|
|
3782
3311
|
}
|
|
3783
3312
|
return ret;
|
|
3784
3313
|
}, {})
|