@wtf/project-config 1.1.1 → 3.0.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.
- package/README.md +40 -34
- package/dist/env.js.map +1 -1
- package/dist/errors.d.ts +4 -18
- package/dist/errors.js +1 -15
- package/dist/errors.js.map +1 -1
- package/dist/files.d.ts +5 -7
- package/dist/files.js +2 -19
- package/dist/files.js.map +1 -1
- package/dist/index.d.ts +4 -21
- package/dist/index.js.map +1 -1
- package/dist/load.d.ts +43 -40
- package/dist/load.js +20 -59
- package/dist/load.js.map +1 -1
- package/dist/locate.d.ts +6 -16
- package/dist/locate.js +9 -13
- package/dist/locate.js.map +1 -1
- package/dist/named.d.ts +4 -2
- package/dist/named.js.map +1 -1
- package/dist/section.d.ts +9 -15
- package/dist/section.js +9 -25
- package/dist/section.js.map +1 -1
- package/dist/write.js +5 -4
- package/dist/write.js.map +1 -1
- package/package.json +5 -9
- package/dist/node.d.ts +0 -35
- package/dist/node.js +0 -139
- package/dist/node.js.map +0 -1
package/dist/node.js
DELETED
|
@@ -1,139 +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
|
-
* Node's platform and loads of the configuration: {@link nodeConfigPlatform}, the disk as handles
|
|
11
|
-
* of the File System Standard, by `nodeStorage()` of `@wtf/platform-fs-node/storage`, and the paths
|
|
12
|
-
* of `nodePath()` of `@wtf/platform-node/path`; {@link nodeSyncPlatform}, the disk read
|
|
13
|
-
* synchronously, by `node:fs`; {@link loadConfig} and {@link loadConfigSync}, those of ./load,
|
|
14
|
-
* of the process's working folder, its environment and Node's platform by default; and
|
|
15
|
-
* {@link nodeLoadModule}, what loads a module a reference of ./named names. A repo loads its config
|
|
16
|
-
* by them, and spreads a section into a preset's options:
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { loadConfig } from '@wtf/project-config/node'
|
|
20
|
-
* import { sectionOf } from '@wtf/project-config/section'
|
|
21
|
-
* import { rootConfig } from '@wtf/project-vitest/config'
|
|
22
|
-
* import { vitestSchema } from '@wtf/project-vitest/schema'
|
|
23
|
-
*
|
|
24
|
-
* const config = await loadConfig()
|
|
25
|
-
* export default rootConfig({ ...(await sectionOf(config, 'vitest', vitestSchema)) })
|
|
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
|
-
import { nodeStorage } from '@wtf/platform-fs-node/storage';
|
|
35
|
-
import { nodePath } from '@wtf/platform-node/path';
|
|
36
|
-
import { loadConfig as loadWith, loadConfigSync as loadSyncWith } from "./load.js";
|
|
37
|
-
/** Node's platform the configuration is read and written by: the disk from its root, its paths,
|
|
38
|
-
* and the process's working folder. */
|
|
39
|
-
export const nodeConfigPlatform = () => ({
|
|
40
|
-
navigator: { storage: nodeStorage() },
|
|
41
|
-
path: nodePath(),
|
|
42
|
-
dirs: { cwd: process.cwd() }
|
|
43
|
-
});
|
|
44
|
-
/** Whether `error` is Node's of a file or a folder not there, or of the other kind. */
|
|
45
|
-
const isMissing = (error) => ['ENOENT', 'ENOTDIR', 'EISDIR'].includes(error?.code ?? '');
|
|
46
|
-
/** Node's platform the configuration is read by synchronously: the disk by `node:fs`, and its
|
|
47
|
-
* paths. */
|
|
48
|
-
export const nodeSyncPlatform = () => ({
|
|
49
|
-
path: nodePath(),
|
|
50
|
-
files: {
|
|
51
|
-
text: (path) => {
|
|
52
|
-
try {
|
|
53
|
-
return readFileSync(path, 'utf8');
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
if (isMissing(error))
|
|
57
|
-
return undefined;
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
files: (folder) => {
|
|
62
|
-
try {
|
|
63
|
-
// A link is what it links to, as a handle of the disk reads it.
|
|
64
|
-
return new Set(readdirSync(folder).filter((name) => {
|
|
65
|
-
try {
|
|
66
|
-
return statSync(join(folder, name)).isFile();
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
if (isMissing(error))
|
|
75
|
-
return new Set();
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
/**
|
|
82
|
-
* The configuration of the project in `folder`, the process's working folder by default, as
|
|
83
|
-
* `loadConfig` of ./load reads it: the namespace `wtf` by default, of Node's platform and the
|
|
84
|
-
* process's environment, unless `options` gives others.
|
|
85
|
-
*/
|
|
86
|
-
export const loadConfig = (folder = process.cwd(), options = {}) => loadWith(folder, {
|
|
87
|
-
environment: process.env,
|
|
88
|
-
...options,
|
|
89
|
-
platform: options.platform ?? nodeConfigPlatform()
|
|
90
|
-
});
|
|
91
|
-
/**
|
|
92
|
-
* The configuration of the project in `folder`, the process's working folder by default, as
|
|
93
|
-
* `loadConfigSync` of ./load reads it, of a JSON file or package.json alone: of Node's platform
|
|
94
|
-
* and the process's environment, unless `options` gives others.
|
|
95
|
-
*/
|
|
96
|
-
export const loadConfigSync = (folder = process.cwd(), options = {}) => loadSyncWith(folder, {
|
|
97
|
-
environment: process.env,
|
|
98
|
-
...options,
|
|
99
|
-
platform: options.platform ?? nodeSyncPlatform()
|
|
100
|
-
});
|
|
101
|
-
/**
|
|
102
|
-
* The file of the module `module`: of an absolute path, itself; of a path from the root, `./` or
|
|
103
|
-
* `../`, of `root`; of a package, the one `root` installs, as a devDependency of the project, else
|
|
104
|
-
* the one installed beside `beside`, as of a global install of a tool and its plugins.
|
|
105
|
-
*/
|
|
106
|
-
function fileOf(module, root, beside) {
|
|
107
|
-
if (isAbsolute(module))
|
|
108
|
-
return module;
|
|
109
|
-
if (/^\.{1,2}\//.test(module))
|
|
110
|
-
return join(root, module);
|
|
111
|
-
try {
|
|
112
|
-
return createRequire(join(root, 'package.json')).resolve(module);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
if (beside === undefined)
|
|
116
|
-
throw error;
|
|
117
|
-
try {
|
|
118
|
-
return createRequire(beside).resolve(module);
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of
|
|
127
|
-
* `root`, the root of the project, the process's working folder by default; a package, the one
|
|
128
|
-
* `root` installs, else the one installed beside `beside`, as a tool gives its own
|
|
129
|
-
* `import.meta.url`, so a package a global install puts beside the tool is found too. What fails
|
|
130
|
-
* to resolve or load fails of the error of `root`'s resolve, or of the import.
|
|
131
|
-
*
|
|
132
|
-
* ```ts
|
|
133
|
-
* import { nodeLoadModule } from '@wtf/project-config/node'
|
|
134
|
-
*
|
|
135
|
-
* const load = nodeLoadModule(process.cwd(), import.meta.url)
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export const nodeLoadModule = (root = process.cwd(), beside) => async (module) => import(__rewriteRelativeImportExtension(pathToFileURL(fileOf(module, root, beside)).href));
|
|
139
|
-
//# sourceMappingURL=node.js.map
|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O,CAAC,QAAQ,IAAI,gBAAgB,EAAE;CACjD,CAAC,CAAA;AAEJ;;;;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,OAAe,OAAO,CAAC,GAAG,EAAE,EAAE,MAAqB,EAAc,EAAE,CACpE,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 * Node's platform and loads of the configuration: {@link nodeConfigPlatform}, the disk as handles\n * of the File System Standard, by `nodeStorage()` of `@wtf/platform-fs-node/storage`, and the paths\n * of `nodePath()` of `@wtf/platform-node/path`; {@link nodeSyncPlatform}, the disk read\n * synchronously, by `node:fs`; {@link loadConfig} and {@link loadConfigSync}, those of ./load,\n * of the process's working folder, its environment and Node's platform by default; and\n * {@link nodeLoadModule}, what loads a module a reference of ./named names. A repo loads its config\n * by them, and spreads a section into a preset's options:\n *\n * ```ts\n * import { loadConfig } from '@wtf/project-config/node'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { rootConfig } from '@wtf/project-vitest/config'\n * import { vitestSchema } from '@wtf/project-vitest/schema'\n *\n * const config = await loadConfig()\n * export default rootConfig({ ...(await sectionOf(config, 'vitest', vitestSchema)) })\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 { nodeStorage } from '@wtf/platform-fs-node/storage'\nimport { nodePath } from '@wtf/platform-node/path'\n\nimport type { ConfigPlatform, ConfigSyncPlatform, ResolvedConfig } from './index.ts'\nimport {\n loadConfig as loadWith,\n loadConfigSync as loadSyncWith,\n type LoadOptions,\n type LoadSyncOptions\n} from './load.ts'\nimport type { LoadModule } from './named.ts'\n\n/** Node's platform the configuration is read and written by: the disk from its root, its paths,\n * and the process's working folder. */\nexport const nodeConfigPlatform = (): ConfigPlatform => ({\n navigator: { storage: nodeStorage() },\n path: nodePath(),\n dirs: { cwd: process.cwd() }\n})\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 platform the configuration is read by synchronously: the disk by `node:fs`, and its\n * paths. */\nexport const nodeSyncPlatform = (): ConfigSyncPlatform => ({\n path: nodePath(),\n files: {\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/**\n * The configuration of the project in `folder`, the process's working folder by default, as\n * `loadConfig` of ./load reads it: the namespace `wtf` by default, of Node's platform and the\n * process's environment, unless `options` gives others.\n */\nexport const loadConfig = (\n folder: string = process.cwd(),\n options: Partial<LoadOptions> = {}\n): Promise<ResolvedConfig> =>\n loadWith(folder, {\n environment: process.env,\n ...options,\n platform: options.platform ?? nodeConfigPlatform()\n })\n\n/**\n * The configuration of the project in `folder`, the process's working folder by default, as\n * `loadConfigSync` of ./load reads it, of a JSON file or package.json alone: of Node's platform\n * and the process's environment, unless `options` gives others.\n */\nexport const loadConfigSync = (\n folder: string = process.cwd(),\n options: Partial<LoadSyncOptions> = {}\n): ResolvedConfig =>\n loadSyncWith(folder, {\n environment: process.env,\n ...options,\n platform: options.platform ?? nodeSyncPlatform()\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, the process's working folder by default; a package, the one\n * `root` installs, else the one installed beside `beside`, as a tool gives its own\n * `import.meta.url`, so a package a global install puts beside the tool is found too. What fails\n * to resolve or load fails 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(process.cwd(), import.meta.url)\n * ```\n */\nexport const nodeLoadModule =\n (root: string = process.cwd(), beside?: string | URL): LoadModule =>\n async (module) =>\n import(pathToFileURL(fileOf(module, root, beside)).href)\n"]}
|