@cubing/dev-config 0.7.0 → 0.7.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.
@@ -0,0 +1,28 @@
1
+ // src/esbuild/es2022/index.ts
2
+ var common = {
3
+ format: "esm",
4
+ target: "es2022",
5
+ bundle: true,
6
+ splitting: true,
7
+ chunkNames: "chunks/[name]-[hash]",
8
+ sourcemap: true
9
+ };
10
+ function es2022App(options) {
11
+ return {
12
+ ...common,
13
+ minify: !options?.dev
14
+ };
15
+ }
16
+ function es2022Lib() {
17
+ return {
18
+ ...es2022App(),
19
+ minify: false,
20
+ packages: "external"
21
+ };
22
+ }
23
+
24
+ export {
25
+ es2022App,
26
+ es2022Lib
27
+ };
28
+ //# sourceMappingURL=chunk-NX2753TH.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/esbuild/es2022/index.ts"],
4
+ "sourcesContent": ["import type { BuildOptions } from \"esbuild\";\n\nconst common = {\n format: \"esm\",\n target: \"es2022\",\n\n bundle: true,\n splitting: true,\n\n chunkNames: \"chunks/[name]-[hash]\",\n sourcemap: true,\n} as const satisfies BuildOptions;\n\nexport function es2022App(options?: { dev?: boolean }): BuildOptions {\n return {\n ...common,\n minify: !options?.dev,\n };\n}\n\nexport function es2022Lib(): BuildOptions {\n return {\n ...es2022App(),\n minify: false,\n packages: \"external\",\n };\n}\n"],
5
+ "mappings": ";AAEA,IAAM,SAAS;AAAA,EACb,QAAQ;AAAA,EACR,QAAQ;AAAA,EAER,QAAQ;AAAA,EACR,WAAW;AAAA,EAEX,YAAY;AAAA,EACZ,WAAW;AACb;AAEO,SAAS,UAAU,SAA2C;AACnE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,CAAC,SAAS;AAAA,EACpB;AACF;AAEO,SAAS,YAA0B;AACxC,SAAO;AAAA,IACL,GAAG,UAAU;AAAA,IACb,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,51 @@
1
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __using = (stack, value, async) => {
6
+ if (value != null) {
7
+ if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
8
+ var dispose, inner;
9
+ if (async) dispose = value[__knownSymbol("asyncDispose")];
10
+ if (dispose === void 0) {
11
+ dispose = value[__knownSymbol("dispose")];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") __typeError("Object not disposable");
15
+ if (inner) dispose = function() {
16
+ try {
17
+ inner.call(this);
18
+ } catch (e) {
19
+ return Promise.reject(e);
20
+ }
21
+ };
22
+ stack.push([async, dispose, value]);
23
+ } else if (async) {
24
+ stack.push([async]);
25
+ }
26
+ return value;
27
+ };
28
+ var __callDispose = (stack, error, hasError) => {
29
+ var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
30
+ return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
31
+ };
32
+ var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
33
+ var next = (it) => {
34
+ while (it = stack.pop()) {
35
+ try {
36
+ var result = it[1] && it[1].call(it[2]);
37
+ if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
38
+ } catch (e) {
39
+ fail(e);
40
+ }
41
+ }
42
+ if (hasError) throw error;
43
+ };
44
+ return next();
45
+ };
46
+
47
+ export {
48
+ __using,
49
+ __callDispose
50
+ };
51
+ //# sourceMappingURL=chunk-OZDRWEHO.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,25 +1,8 @@
1
- // src/esbuild/es2022/index.ts
2
- var common = {
3
- format: "esm",
4
- target: "es2022",
5
- bundle: true,
6
- splitting: true,
7
- chunkNames: "chunks/[name]-[hash]",
8
- sourcemap: true
9
- };
10
- function es2022App(options) {
11
- return {
12
- ...common,
13
- minify: !options?.dev
14
- };
15
- }
16
- function es2022Lib() {
17
- return {
18
- ...es2022App(),
19
- minify: false,
20
- packages: "external"
21
- };
22
- }
1
+ import {
2
+ es2022App,
3
+ es2022Lib
4
+ } from "../../chunks/chunk-NX2753TH.js";
5
+ import "../../chunks/chunk-OZDRWEHO.js";
23
6
  export {
24
7
  es2022App,
25
8
  es2022Lib
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/esbuild/es2022/index.ts"],
4
- "sourcesContent": ["import type { BuildOptions } from \"esbuild\";\n\nconst common = {\n format: \"esm\",\n target: \"es2022\",\n\n bundle: true,\n splitting: true,\n\n chunkNames: \"chunks/[name]-[hash]\",\n sourcemap: true,\n} as const satisfies BuildOptions;\n\nexport function es2022App(options?: { dev?: boolean }): BuildOptions {\n return {\n ...common,\n minify: !options?.dev,\n };\n}\n\nexport function es2022Lib(): BuildOptions {\n return {\n ...es2022App(),\n minify: false,\n packages: \"external\",\n };\n}\n"],
5
- "mappings": ";AAEA,IAAM,SAAS;AAAA,EACb,QAAQ;AAAA,EACR,QAAQ;AAAA,EAER,QAAQ;AAAA,EACR,WAAW;AAAA,EAEX,YAAY;AAAA,EACZ,WAAW;AACb;AAEO,SAAS,UAAU,SAA2C;AACnE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,CAAC,SAAS;AAAA,EACpB;AACF;AAEO,SAAS,YAA0B;AACxC,SAAO;AAAA,IACL,GAAG,UAAU;AAAA,IACb,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;",
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,20 @@
1
+ import { type BuildOptions } from "esbuild";
2
+ /**
3
+ * Note:
4
+ * - A file may be matched by any parent path scope key.
5
+ * - Files in a given scope key are allowed to import any other within the same scope.
6
+ */
7
+ export type AllowedImports = {
8
+ [scope: string]: {
9
+ static?: string[];
10
+ dynamic?: string[];
11
+ };
12
+ };
13
+ export declare function checkAllowedImports(groups: {
14
+ [description: string]: {
15
+ entryPoints: string[];
16
+ allowedImports: AllowedImports;
17
+ };
18
+ }, options?: {
19
+ overrideEsbuildOptions: BuildOptions;
20
+ }): Promise<void>;
@@ -0,0 +1 @@
1
+ export { type AllowedImports, checkAllowedImports, } from "./checkAllowedImports";
@@ -0,0 +1,113 @@
1
+ import {
2
+ es2022Lib
3
+ } from "../../chunks/chunk-NX2753TH.js";
4
+ import "../../chunks/chunk-OZDRWEHO.js";
5
+
6
+ // src/lib/check-allowed-imports/checkAllowedImports.ts
7
+ import {
8
+ build
9
+ } from "esbuild";
10
+ import { Path } from "path-class";
11
+ var plugin = {
12
+ name: "mark-bare-imports-as-external",
13
+ setup(build2) {
14
+ const filter = /^[^./]|^\.[^./]|^\.\.[^/]/;
15
+ build2.onResolve({ filter }, (args) => ({
16
+ path: args.path,
17
+ external: true
18
+ }));
19
+ }
20
+ };
21
+ async function checkAllowedImports(groups, options) {
22
+ let failure = false;
23
+ console.log("+ means a new file");
24
+ console.log("- means a valid import for that file");
25
+ for (const [description, { entryPoints, allowedImports }] of Object.entries(
26
+ groups
27
+ )) {
28
+ let matchingPathPrefix2 = function(matchPrefixes, path) {
29
+ for (const pathPrefix of pathPrefixes(path)) {
30
+ if (matchPrefixes.includes(pathPrefix)) {
31
+ return pathPrefix;
32
+ }
33
+ }
34
+ return false;
35
+ }, checkImport2 = function(sourcePath, importInfo, allowedImports2) {
36
+ const importKind = importKindMap[importInfo.kind];
37
+ if (!importKind) {
38
+ throw new Error("Unexpected import kind!");
39
+ }
40
+ for (const sourcePathPrefix of pathPrefixes(sourcePath)) {
41
+ const matchingSourcePathPrefix = matchingPathPrefix2(
42
+ Object.keys(allowedImports2),
43
+ sourcePathPrefix
44
+ );
45
+ if (matchingSourcePathPrefix) {
46
+ const allowedImportsForKind = allowedImports2[matchingSourcePathPrefix][importKind];
47
+ if (typeof allowedImportsForKind !== "undefined" && !Array.isArray(allowedImportsForKind)) {
48
+ throw new Error(
49
+ `Expected a string list for ${importKind} imports under the scope "${matchingSourcePathPrefix}"`
50
+ );
51
+ }
52
+ if (matchingPathPrefix2(
53
+ [
54
+ matchingSourcePathPrefix,
55
+ // allow importing from any source group to itself.
56
+ ...allowedImportsForKind ?? []
57
+ ],
58
+ importInfo.path
59
+ )) {
60
+ process.stdout.write("-");
61
+ return;
62
+ }
63
+ }
64
+ }
65
+ failure = true;
66
+ console.error(`
67
+ \u274C File has disallowed ${importKind} import:`);
68
+ console.error(`From file: ${sourcePath}`);
69
+ console.error(`Importing: ${importInfo.path}`);
70
+ };
71
+ var matchingPathPrefix = matchingPathPrefix2, checkImport = checkImport2;
72
+ console.log(`# ${description}`);
73
+ const { metafile } = await build({
74
+ ...es2022Lib(),
75
+ entryPoints,
76
+ plugins: [plugin],
77
+ ...options?.overrideEsbuildOptions,
78
+ // Bogus `outdir` to avoid an error.
79
+ outdir: (await Path.makeTempDir()).path,
80
+ write: false,
81
+ metafile: true
82
+ });
83
+ function* pathPrefixes(path) {
84
+ const pathParts = path.split("/");
85
+ for (let n = pathParts.length; n > 0; n--) {
86
+ yield pathParts.slice(0, n).join("/");
87
+ }
88
+ }
89
+ const importKindMap = {
90
+ "import-statement": "static",
91
+ "dynamic-import": "dynamic"
92
+ };
93
+ async function checkImports(metafile2, allowedImports2) {
94
+ for (const [filePath, importInfoList] of Object.entries(
95
+ metafile2.inputs
96
+ )) {
97
+ process.stdout.write("+");
98
+ for (const importInfo of importInfoList.imports) {
99
+ checkImport2(filePath, importInfo, allowedImports2);
100
+ }
101
+ }
102
+ console.log();
103
+ }
104
+ await checkImports(metafile, allowedImports);
105
+ }
106
+ if (failure) {
107
+ throw new Error("Failure");
108
+ }
109
+ }
110
+ export {
111
+ checkAllowedImports
112
+ };
113
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/check-allowed-imports/checkAllowedImports.ts"],
4
+ "sourcesContent": ["import {\n type BuildOptions,\n build,\n type ImportKind,\n type Metafile,\n type Plugin,\n} from \"esbuild\";\nimport { Path } from \"path-class\";\nimport { es2022Lib } from \"../../esbuild/es2022\";\n\n/**\n * Note:\n * - A file may be matched by any parent path scope key.\n * - Files in a given scope key are allowed to import any other within the same scope.\n */\nexport type AllowedImports = {\n [scope: string]: { static?: string[]; dynamic?: string[] };\n};\n\nconst plugin = {\n name: \"mark-bare-imports-as-external\",\n setup(build) {\n const filter = /^[^./]|^\\.[^./]|^\\.\\.[^/]/; // Must not start with \"/\" or \"./\" or \"../\"\n build.onResolve({ filter }, (args) => ({\n path: args.path,\n external: true,\n }));\n },\n} satisfies Plugin;\n\nexport async function checkAllowedImports(\n groups: {\n [description: string]: {\n entryPoints: string[];\n allowedImports: AllowedImports;\n };\n },\n options?: { overrideEsbuildOptions: BuildOptions },\n): Promise<void> {\n let failure = false;\n\n console.log(\"+ means a new file\");\n console.log(\"- means a valid import for that file\");\n\n for (const [description, { entryPoints, allowedImports }] of Object.entries(\n groups,\n )) {\n console.log(`# ${description}`);\n // From https://github.com/evanw/esbuild/issues/619#issuecomment-1504100390\n\n const { metafile } = await build({\n ...es2022Lib(),\n entryPoints,\n plugins: [plugin],\n ...options?.overrideEsbuildOptions,\n // Bogus `outdir` to avoid an error.\n outdir: (await Path.makeTempDir()).path,\n write: false,\n metafile: true,\n });\n\n // Starts with the path and then keeps chopping off from the right.\n function* pathPrefixes(path: string) {\n const pathParts = path.split(\"/\");\n for (let n = pathParts.length; n > 0; n--) {\n yield pathParts.slice(0, n).join(\"/\");\n }\n }\n\n function matchingPathPrefix(matchPrefixes: string[], path: string) {\n for (const pathPrefix of pathPrefixes(path)) {\n if (matchPrefixes.includes(pathPrefix)) {\n return pathPrefix;\n }\n }\n return false;\n }\n\n const importKindMap: Partial<Record<ImportKind, \"static\" | \"dynamic\">> = {\n \"import-statement\": \"static\",\n \"dynamic-import\": \"dynamic\",\n } as const;\n\n function checkImport(\n sourcePath: string,\n importInfo: {\n path: string;\n kind: ImportKind;\n external?: boolean;\n original?: string;\n },\n allowedImports: AllowedImports,\n ) {\n const importKind = importKindMap[importInfo.kind];\n if (!importKind) {\n throw new Error(\"Unexpected import kind!\");\n }\n for (const sourcePathPrefix of pathPrefixes(sourcePath)) {\n const matchingSourcePathPrefix = matchingPathPrefix(\n Object.keys(allowedImports),\n sourcePathPrefix,\n );\n if (matchingSourcePathPrefix) {\n const allowedImportsForKind =\n allowedImports[matchingSourcePathPrefix][importKind];\n if (\n typeof allowedImportsForKind !== \"undefined\" &&\n !Array.isArray(allowedImportsForKind)\n ) {\n throw new Error(\n `Expected a string list for ${importKind} imports under the scope \"${matchingSourcePathPrefix}\"`,\n );\n }\n if (\n matchingPathPrefix(\n [\n matchingSourcePathPrefix, // allow importing from any source group to itself.\n ...(allowedImportsForKind ?? []),\n ],\n importInfo.path,\n )\n ) {\n process.stdout.write(\"-\");\n return;\n }\n }\n }\n failure = true;\n console.error(`\\n\u274C File has disallowed ${importKind} import:`);\n console.error(`From file: ${sourcePath}`);\n console.error(`Importing: ${importInfo.path}`);\n }\n\n async function checkImports(\n metafile: Metafile,\n allowedImports: AllowedImports,\n ) {\n for (const [filePath, importInfoList] of Object.entries(\n metafile.inputs,\n )) {\n process.stdout.write(\"+\");\n for (const importInfo of importInfoList.imports) {\n checkImport(filePath, importInfo, allowedImports);\n }\n }\n console.log();\n }\n\n await checkImports(metafile, allowedImports);\n }\n\n if (failure) {\n throw new Error(\"Failure\");\n }\n}\n"],
5
+ "mappings": ";;;;;;AAAA;AAAA,EAEE;AAAA,OAIK;AACP,SAAS,YAAY;AAYrB,IAAM,SAAS;AAAA,EACb,MAAM;AAAA,EACN,MAAMA,QAAO;AACX,UAAM,SAAS;AACf,IAAAA,OAAM,UAAU,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AQ,MAAM,cAAc,WAAW,IAAI,EAAE;AAAA,IAC/C;AA9DS,6BAAAA,qBAcA,cAAAC;AApCT,YAAQ,IAAI,KAAK,WAAW,EAAE;AAG9B,UAAM,EAAE,SAAS,IAAI,MAAM,MAAM;AAAA,MAC/B,GAAG,UAAU;AAAA,MACb;AAAA,MACA,SAAS,CAAC,MAAM;AAAA,MAChB,GAAG,SAAS;AAAA;AAAA,MAEZ,SAAS,MAAM,KAAK,YAAY,GAAG;AAAA,MACnC,OAAO;AAAA,MACP,UAAU;AAAA,IACZ,CAAC;AAGD,cAAU,aAAa,MAAc;AACnC,YAAM,YAAY,KAAK,MAAM,GAAG;AAChC,eAAS,IAAI,UAAU,QAAQ,IAAI,GAAG,KAAK;AACzC,cAAM,UAAU,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG;AAAA,MACtC;AAAA,IACF;AAWA,UAAM,gBAAmE;AAAA,MACvE,oBAAoB;AAAA,MACpB,kBAAkB;AAAA,IACpB;AAoDA,mBAAe,aACbE,WACAD,iBACA;AACA,iBAAW,CAAC,UAAU,cAAc,KAAK,OAAO;AAAA,QAC9CC,UAAS;AAAA,MACX,GAAG;AACD,gBAAQ,OAAO,MAAM,GAAG;AACxB,mBAAW,cAAc,eAAe,SAAS;AAC/C,UAAAF,aAAY,UAAU,YAAYC,eAAc;AAAA,QAClD;AAAA,MACF;AACA,cAAQ,IAAI;AAAA,IACd;AAEA,UAAM,aAAa,UAAU,cAAc;AAAA,EAC7C;AAEA,MAAI,SAAS;AACX,UAAM,IAAI,MAAM,SAAS;AAAA,EAC3B;AACF;",
6
+ "names": ["build", "matchingPathPrefix", "checkImport", "allowedImports", "metafile"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubing/dev-config",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Common dev configs for projects.",
5
5
  "author": {
6
6
  "name": "Lucas Garron",
@@ -19,11 +19,12 @@
19
19
  "import": "./esbuild/es2022/index.js"
20
20
  },
21
21
  "./check-allowed-imports": {
22
- "default": "./lib/check-allowed-imports/index.ts"
22
+ "types": "./lib/check-allowed-imports/index.d.ts",
23
+ "default": "./lib/check-allowed-imports/index.js"
23
24
  }
24
25
  },
25
26
  "bin": {
26
- "package.json": "bin/package.json.ts"
27
+ "package.json": "bin/package.json/index.js"
27
28
  },
28
29
  "dependencies": {
29
30
  "esbuild": ">=0.25.3 && <1.0.0",
@@ -38,7 +39,9 @@
38
39
  "typescript": "^5.9.3"
39
40
  },
40
41
  "files": [
42
+ "./bin/",
41
43
  "./biome/",
44
+ "./chunks/",
42
45
  "./esbuild/",
43
46
  "./lib",
44
47
  "./ts/"