@wtf/project-config 2.0.0 → 3.0.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@wtf/project-config",
3
- "version": "2.0.0",
4
- "description": "Read and write a project's configuration of its tools: one object under a namespace, wtf by default, with a section for each tool, in wtf.config.{mjs,js,ts,json} or the wtf key of package.json, the first found. Find it (./locate); load it, asynchronously with code, or synchronously of JSON and package.json alone (./load); read a tool's section, checked by its Standard Schema, a JSON Schema or a function, with WTF_<SECTION>_<KEY> variables over it (./section, ./env); replace ${env:NAME} placeholders (./placeholder); get a value by its path (./path); write a value (./write); the JSON Schema of the whole (./schema); a code config, typed (./define); a value or a function named in JSON, by a name, a name with options or the export of a module, of sets merged in order (./named); Node's platform, loads and loader of modules (./node); and the errors (./errors).",
3
+ "version": "3.0.1",
4
+ "description": "Read and write a project's configuration of its tools: one object under a namespace, wtf by default, with a section for each tool, in wtf.config.{mjs,js,ts,json} or the wtf key of package.json, the first found. Find it (./locate); load it, of code or of JSON (./load); read a tool's section, checked by its Standard Schema, a JSON Schema or a function, with WTF_<SECTION>_<KEY> variables over it (./section, ./env); replace ${env:NAME} placeholders (./placeholder); get a value by its path (./path); write a value (./write); the JSON Schema of the whole (./schema); a code config, typed (./define); a value or a function named in JSON, by a name, a name with options or the export of a module, of sets merged in order, its modules loaded by the loader you pass (./named); and the errors (./errors).",
5
5
  "homepage": "https://gitlab.com/wetryfun/project/project/-/tree/main/packages/project-config",
6
6
  "bugs": {
7
7
  "url": "https://gitlab.com/wetryfun/project/project/-/issues"
@@ -62,10 +62,6 @@
62
62
  "types": "./dist/named.d.ts",
63
63
  "default": "./dist/named.js"
64
64
  },
65
- "./node": {
66
- "types": "./dist/node.d.ts",
67
- "default": "./dist/node.js"
68
- },
69
65
  "./errors": {
70
66
  "types": "./dist/errors.d.ts",
71
67
  "default": "./dist/errors.js"
@@ -79,15 +75,15 @@
79
75
  },
80
76
  "dependencies": {
81
77
  "@standard-schema/spec": "^1.1.0",
82
- "@wtf/platform": "^2.0.0",
83
- "@wtf/platform-fs": "^1.1.0",
78
+ "@wtf/platform": "^3.0.0",
79
+ "@wtf/platform-fs": "^1.1.1",
84
80
  "ajv": "^8.20.0",
85
81
  "jsonc-parser": "^3.3.1"
86
82
  },
87
83
  "devDependencies": {
88
- "@wtf/platform-fs-memory": "^1.1.0",
89
- "@wtf/platform-fs-node": "^1.1.0",
90
- "@wtf/platform-node": "^2.0.0"
84
+ "@wtf/platform-fs-memory": "^1.1.1",
85
+ "@wtf/platform-fs-node": "^1.1.1",
86
+ "@wtf/platform-node": "^3.0.0"
91
87
  },
92
88
  "engines": {
93
89
  "node": ">=24.15.0"
package/dist/node.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { LoadSyncPlatform } from './load.ts';
2
- import type { LoadModule } from './named.ts';
3
- /**
4
- * The platform the configuration is read by synchronously, of `platform`: its paths, its working
5
- * folder and its environment, as they are, and the disk, read synchronously by `node:fs`, as its
6
- * files. `loadConfigSync` of ./load reads by it.
7
- */
8
- export declare const nodeSyncPlatform: ({ path, dirs, env }: Omit<LoadSyncPlatform, "files">) => LoadSyncPlatform;
9
- /**
10
- * Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of
11
- * `root`, the root of the project, as the entry point gives it; a package, the one `root`
12
- * installs, else the one installed beside `beside`, as a tool gives its own `import.meta.url`, so a
13
- * package a global install puts beside the tool is found too. What fails to resolve or load fails
14
- * of the error of `root`'s resolve, or of the import.
15
- *
16
- * ```ts
17
- * import { nodeLoadModule } from '@wtf/project-config/node'
18
- *
19
- * const load = nodeLoadModule(resolved.root, import.meta.url)
20
- * ```
21
- */
22
- export declare const nodeLoadModule: (root: string, beside?: string | URL) => LoadModule;
package/dist/node.js DELETED
@@ -1,116 +0,0 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- /**
10
- * What of the configuration is Node's by nature: {@link nodeSyncPlatform}, a platform's files read
11
- * synchronously, by `node:fs`, as no handle of the File System Standard reads them, for
12
- * `loadConfigSync` of ./load; and {@link nodeLoadModule}, what loads a module a reference of
13
- * ./named names, by Node's resolution and `import()`. Neither reads anything of the process: the
14
- * entry point gives the platform, and the root of the project:
15
- *
16
- * ```ts
17
- * import { nodeStorage } from '@wtf/platform-fs-node/storage'
18
- * import { nodePlatform } from '@wtf/platform-node/platform'
19
- *
20
- * import { loadConfigSync } from '@wtf/project-config/load'
21
- * import { nodeLoadModule, nodeSyncPlatform } from '@wtf/project-config/node'
22
- *
23
- * const platform = nodePlatform({ fetch, storage: nodeStorage() })
24
- * const resolved = loadConfigSync({ platform: nodeSyncPlatform(platform) })
25
- * const load = nodeLoadModule(resolved.root, import.meta.url)
26
- * ```
27
- *
28
- * @packageDocumentation
29
- */
30
- import { readdirSync, readFileSync, statSync } from 'node:fs';
31
- import { createRequire } from 'node:module';
32
- import { isAbsolute, join } from 'node:path';
33
- import { pathToFileURL } from 'node:url';
34
- /** Whether `error` is Node's of a file or a folder not there, or of the other kind. */
35
- const isMissing = (error) => ['ENOENT', 'ENOTDIR', 'EISDIR'].includes(error?.code ?? '');
36
- /** Node's files, read synchronously by `node:fs`, by their absolute paths. */
37
- const nodeSyncFiles = {
38
- text: (path) => {
39
- try {
40
- return readFileSync(path, 'utf8');
41
- }
42
- catch (error) {
43
- if (isMissing(error))
44
- return undefined;
45
- throw error;
46
- }
47
- },
48
- files: (folder) => {
49
- try {
50
- // A link is what it links to, as a handle of the disk reads it.
51
- return new Set(readdirSync(folder).filter((name) => {
52
- try {
53
- return statSync(join(folder, name)).isFile();
54
- }
55
- catch {
56
- return false;
57
- }
58
- }));
59
- }
60
- catch (error) {
61
- if (isMissing(error))
62
- return new Set();
63
- throw error;
64
- }
65
- }
66
- };
67
- /**
68
- * The platform the configuration is read by synchronously, of `platform`: its paths, its working
69
- * folder and its environment, as they are, and the disk, read synchronously by `node:fs`, as its
70
- * files. `loadConfigSync` of ./load reads by it.
71
- */
72
- export const nodeSyncPlatform = ({ path, dirs, env }) => ({
73
- path,
74
- dirs,
75
- env,
76
- files: nodeSyncFiles
77
- });
78
- /**
79
- * The file of the module `module`: of an absolute path, itself; of a path from the root, `./` or
80
- * `../`, of `root`; of a package, the one `root` installs, as a devDependency of the project, else
81
- * the one installed beside `beside`, as of a global install of a tool and its plugins.
82
- */
83
- function fileOf(module, root, beside) {
84
- if (isAbsolute(module))
85
- return module;
86
- if (/^\.{1,2}\//.test(module))
87
- return join(root, module);
88
- try {
89
- return createRequire(join(root, 'package.json')).resolve(module);
90
- }
91
- catch (error) {
92
- if (beside === undefined)
93
- throw error;
94
- try {
95
- return createRequire(beside).resolve(module);
96
- }
97
- catch {
98
- throw error;
99
- }
100
- }
101
- }
102
- /**
103
- * Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of
104
- * `root`, the root of the project, as the entry point gives it; a package, the one `root`
105
- * installs, else the one installed beside `beside`, as a tool gives its own `import.meta.url`, so a
106
- * package a global install puts beside the tool is found too. What fails to resolve or load fails
107
- * of the error of `root`'s resolve, or of the import.
108
- *
109
- * ```ts
110
- * import { nodeLoadModule } from '@wtf/project-config/node'
111
- *
112
- * const load = nodeLoadModule(resolved.root, import.meta.url)
113
- * ```
114
- */
115
- export const nodeLoadModule = (root, beside) => async (module) => import(__rewriteRelativeImportExtension(pathToFileURL(fileOf(module, root, beside)).href));
116
- //# sourceMappingURL=node.js.map
package/dist/node.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources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AC;gBAAE,OAAO,IAAI,GAAG,EAAU,CAAA;YAC9C,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EACJ,IAAI,EACJ,GAAG,EAC6B,EAAoB,EAAE,CAAC,CAAC;IACxD,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,KAAK,EAAE,aAAa;CACrB,CAAC,CAAA;AAEF;;;;GAIG;AACH,SAAS,MAAM,CAAC,MAAc,EAAE,IAAY,EAAE,MAAgC;IAC5E,IAAI,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACrC,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACxD,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,KAAK,CAAA;QACrC,IAAI,CAAC;YACH,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,CAAC,IAAY,EAAE,MAAqB,EAAc,EAAE,CACpD,KAAK,EAAE,MAAM,EAAE,EAAE,CACf,MAAM,kCAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAC,CAAA","sourcesContent":["/**\n * What of the configuration is Node's by nature: {@link nodeSyncPlatform}, a platform's files read\n * synchronously, by `node:fs`, as no handle of the File System Standard reads them, for\n * `loadConfigSync` of ./load; and {@link nodeLoadModule}, what loads a module a reference of\n * ./named names, by Node's resolution and `import()`. Neither reads anything of the process: the\n * entry point gives the platform, and the root of the project:\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfigSync } from '@wtf/project-config/load'\n * import { nodeLoadModule, nodeSyncPlatform } from '@wtf/project-config/node'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const resolved = loadConfigSync({ platform: nodeSyncPlatform(platform) })\n * const load = nodeLoadModule(resolved.root, import.meta.url)\n * ```\n *\n * @packageDocumentation\n */\nimport { readdirSync, readFileSync, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { isAbsolute, join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\nimport type { SyncFiles } from './index.ts'\nimport type { LoadSyncPlatform } from './load.ts'\nimport type { LoadModule } from './named.ts'\n\n/** Whether `error` is Node's of a file or a folder not there, or of the other kind. */\nconst isMissing = (error: unknown): boolean =>\n ['ENOENT', 'ENOTDIR', 'EISDIR'].includes((error as NodeJS.ErrnoException | undefined)?.code ?? '')\n\n/** Node's files, read synchronously by `node:fs`, by their absolute paths. */\nconst nodeSyncFiles: SyncFiles = {\n text: (path) => {\n try {\n return readFileSync(path, 'utf8')\n } catch (error) {\n if (isMissing(error)) return undefined\n throw error\n }\n },\n files: (folder) => {\n try {\n // A link is what it links to, as a handle of the disk reads it.\n return new Set(\n readdirSync(folder).filter((name) => {\n try {\n return statSync(join(folder, name)).isFile()\n } catch {\n return false\n }\n })\n )\n } catch (error) {\n if (isMissing(error)) return new Set<string>()\n throw error\n }\n }\n}\n\n/**\n * The platform the configuration is read by synchronously, of `platform`: its paths, its working\n * folder and its environment, as they are, and the disk, read synchronously by `node:fs`, as its\n * files. `loadConfigSync` of ./load reads by it.\n */\nexport const nodeSyncPlatform = ({\n path,\n dirs,\n env\n}: Omit<LoadSyncPlatform, 'files'>): LoadSyncPlatform => ({\n path,\n dirs,\n env,\n files: nodeSyncFiles\n})\n\n/**\n * The file of the module `module`: of an absolute path, itself; of a path from the root, `./` or\n * `../`, of `root`; of a package, the one `root` installs, as a devDependency of the project, else\n * the one installed beside `beside`, as of a global install of a tool and its plugins.\n */\nfunction fileOf(module: string, root: string, beside: string | URL | undefined): string {\n if (isAbsolute(module)) return module\n if (/^\\.{1,2}\\//.test(module)) return join(root, module)\n try {\n return createRequire(join(root, 'package.json')).resolve(module)\n } catch (error) {\n if (beside === undefined) throw error\n try {\n return createRequire(beside).resolve(module)\n } catch {\n throw error\n }\n }\n}\n\n/**\n * Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of\n * `root`, the root of the project, as the entry point gives it; a package, the one `root`\n * installs, else the one installed beside `beside`, as a tool gives its own `import.meta.url`, so a\n * package a global install puts beside the tool is found too. What fails to resolve or load fails\n * of the error of `root`'s resolve, or of the import.\n *\n * ```ts\n * import { nodeLoadModule } from '@wtf/project-config/node'\n *\n * const load = nodeLoadModule(resolved.root, import.meta.url)\n * ```\n */\nexport const nodeLoadModule =\n (root: string, beside?: string | URL): LoadModule =>\n async (module) =>\n import(pathToFileURL(fileOf(module, root, beside)).href)\n"]}