@cldmv/wisp 1.0.9 → 2.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 +9 -6
- package/dist/index.cjs +19 -17
- package/dist/index.mjs +2 -2
- package/dist/lib/resolve-from-caller.mjs +2 -0
- package/dist/wisp.mjs +2 -0
- package/package.json +12 -11
- package/types/lib/resolve-from-caller.d.mts.map +1 -1
package/README.md
CHANGED
|
@@ -14,18 +14,19 @@ Relative paths resolve from the file that calls wisp, not from wisp's own locati
|
|
|
14
14
|
|
|
15
15
|
## ✨ What's New
|
|
16
16
|
|
|
17
|
-
### Latest:
|
|
17
|
+
### Latest: v2.0.0 (November 2026)
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
- **
|
|
21
|
-
-
|
|
19
|
+
- **`require("@cldmv/wisp")` returns the module object** — the CommonJS entry now gives back `{ default, wisp, wispSync }`, the same exports as `import`, instead of the `wisp` function. Change `require(x)(…)` to `require(x).wisp(…)` or `const { wisp } = require(x)`; `.wisp`, `.wispSync`, `.default` and destructuring keep working, and ESM `import` is unchanged ([#86](https://github.com/CLDMV/wisp/pull/86)).
|
|
20
|
+
- **Tests also run against the build** — `npm test` now includes `test:dist`, which builds the package and runs the suite against `dist/` ([#74](https://github.com/CLDMV/wisp/pull/74)).
|
|
21
|
+
- **`dist/` is built one file per module** — the tsup bundle is replaced by a per-file esbuild build that mirrors `src/`; the `require()` and `import` shapes are unchanged ([#91](https://github.com/CLDMV/wisp/pull/91)).
|
|
22
|
+
- [View full v2.0.0 Changelog](https://github.com/CLDMV/wisp/blob/master/docs/changelog/v2/v2.0.0.md)
|
|
22
23
|
|
|
23
24
|
### Recent Releases
|
|
24
25
|
|
|
26
|
+
- **v1.0.9** (November 2026) — CommonJS entry renamed to `src/index.cjs` in source, caller-resolution tests through it, and the Node.js 22.22 development floor in `devEngines`; no change for consumers ([Changelog](https://github.com/CLDMV/wisp/blob/master/docs/changelog/v1/v1.0.9.md))
|
|
25
27
|
- **v1.0.8** (October 2026) — Development-dependency patch (`@types/node` 26.6.4); no runtime change ([Changelog](https://github.com/CLDMV/wisp/blob/master/docs/changelog/v1/v1.0.8.md))
|
|
26
28
|
- **v1.0.7** (October 2026) — `require()` works inside esbuild and webpack bundles and fails clearly on older Node.js; a failed `validate` throws instead of loading the `fallback`; the package is now built into `dist/` and relicensed under Apache-2.0 ([Changelog](https://github.com/CLDMV/wisp/blob/master/docs/changelog/v1/v1.0.7.md))
|
|
27
29
|
- **v1.0.6** (October 2026) — Uniform file headers via `@cldmv/fix-headers`, a CI fix and a development-dependency security update; no runtime change ([Changelog](https://github.com/CLDMV/wisp/blob/master/docs/changelog/v1/v1.0.6.md))
|
|
28
|
-
- **v1.0.5** (October 2026) — First npm release since v1.0.1; TypeScript 6, chai 6 and `@types/node` 26 for development, v4 workflow syncs; no runtime change ([Changelog](https://github.com/CLDMV/wisp/blob/master/docs/changelog/v1/v1.0.5.md))
|
|
29
30
|
|
|
30
31
|
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/wisp/tree/master/docs/changelog/) folder.**
|
|
31
32
|
|
|
@@ -97,6 +98,8 @@ wisp("./config.json").then((config) => {
|
|
|
97
98
|
const data = wispSync("./data.json");
|
|
98
99
|
```
|
|
99
100
|
|
|
101
|
+
`require("@cldmv/wisp")` returns the module object, the same exports as `import`: `{ default, wisp, wispSync }`. It is not the `wisp` function itself, so call `require("@cldmv/wisp").wisp(...)` (or destructure as above); `.default` is the same function as `.wisp`.
|
|
102
|
+
|
|
100
103
|
---
|
|
101
104
|
|
|
102
105
|
## 📖 API Reference
|
|
@@ -224,7 +227,7 @@ try {
|
|
|
224
227
|
|
|
225
228
|
Contributions are welcome — open an [issue](https://github.com/CLDMV/wisp/issues) or a pull request.
|
|
226
229
|
|
|
227
|
-
In a checkout, the package name resolves to the built `dist/` (run `npm run build` first). The `wisp-dev` export condition switches it to the source in `src/`: `src/index.mjs` for `import`, `src/index.cjs` for `require()`. Pass it per command (`node --conditions=wisp-dev app.mjs`) or once per shell (`export NODE_OPTIONS=--conditions=wisp-dev`). The test scripts set it themselves
|
|
230
|
+
In a checkout, the package name resolves to the built `dist/` (run `npm run build` first). The `wisp-dev` export condition switches it to the source in `src/`: `src/index.mjs` for `import`, `src/index.cjs` for `require()`. Pass it per command (`node --conditions=wisp-dev app.mjs`) or once per shell (`export NODE_OPTIONS=--conditions=wisp-dev`). The test scripts set it themselves: `npm test` runs the suite against `src/`, and `npm run test:dist` builds the package and runs it against `dist/`.
|
|
228
231
|
|
|
229
232
|
[![Contributors]][contributors_url] [![Sponsor shinrai]][sponsor_url]
|
|
230
233
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* @Project: @cldmv/wisp
|
|
4
|
-
* @Filename:
|
|
4
|
+
* @Filename: src/index.cjs
|
|
5
5
|
* @Date: 2025-10-30T15:06:33-07:00 (1761861993)
|
|
6
6
|
* @Author: Nate Corcoran <CLDMV>
|
|
7
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
8
|
* -----
|
|
9
9
|
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-11-
|
|
10
|
+
* @Last modified time: 2026-11-28T09:53:26-08:00 (1795888406)
|
|
11
11
|
* -----
|
|
12
12
|
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
13
|
*
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
* @public
|
|
20
20
|
*
|
|
21
21
|
* @description
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* Generic CLDMV CommonJS shim: it loads ./index.mjs through Node's synchronous require(esm) and
|
|
23
|
+
* hands back the same exports as `import`. The ESM entry exports two distinct values (`wisp` and
|
|
24
|
+
* `wispSync`; `default` is `wisp`), so require() returns the module object
|
|
25
|
+
* `{ __esModule, default: wisp, wisp, wispSync }`, not a callable. It is not bundled: tsup copies it
|
|
26
|
+
* verbatim to dist/index.cjs, where ./index.mjs is the ESM bundle; under the `wisp-dev` export
|
|
27
|
+
* condition it is served from src/, where ./index.mjs is the source entry.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* const { wisp, wispSync } = require('@cldmv/wisp');
|
|
@@ -33,10 +33,9 @@
|
|
|
33
33
|
|
|
34
34
|
"use strict";
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
// because Node.js 22.12 has require(esm) but prints an ExperimentalWarning on every use.
|
|
36
|
+
// Node.js versions without require(esm) would fail with a bare ERR_REQUIRE_ESM, so fail early with a
|
|
37
|
+
// message that says what to do instead. The floor is 22.13 rather than 22.12 because Node.js 22.12
|
|
38
|
+
// has require(esm) but prints an ExperimentalWarning on every use.
|
|
40
39
|
if (!process.features?.require_module) {
|
|
41
40
|
const error = new Error(
|
|
42
41
|
`@cldmv/wisp: require() needs Node.js ^20.19.0 or >=22.13.0 (this is ${process.version}). On older Node.js, load the package with import() instead.`
|
|
@@ -45,9 +44,12 @@ if (!process.features?.require_module) {
|
|
|
45
44
|
throw error;
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
// Same exports as `import`. One distinct exported value (aliases of it count once) comes back as that value,
|
|
48
|
+
// so require(x)(...) works; anything else comes back as the module object ({ default, ...named }).
|
|
48
49
|
const esm = require("./index.mjs");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const values = new Set(
|
|
51
|
+
Object.keys(esm)
|
|
52
|
+
.filter((key) => key !== "__esModule")
|
|
53
|
+
.map((key) => esm[key])
|
|
54
|
+
);
|
|
55
|
+
module.exports = values.size === 1 ? values.values().next().value : esm;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export*from"./wisp.mjs";import{default as f}from"./wisp.mjs";export{f as default};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var F=Object.defineProperty;var a=(t,e)=>F(t,"name",{value:e,configurable:!0});import p from"node:fs";import o from"node:path";import{fileURLToPath as f,pathToFileURL as l}from"node:url";const S=a(t=>t&&String(t).startsWith("file://")?f(String(t)):t?String(t):null,"toFsPath");function g(t){const e=Error.prepareStackTrace;try{Error.prepareStackTrace=(n,i)=>i;const r=new Error("Stack trace");return t&&Error.captureStackTrace(r,t),r.stack||[]}finally{Error.prepareStackTrace=e}}a(g,"getStack");const u=f(import.meta.url);function d(t){let e=t;for(;e!==o.dirname(e);){const r=o.join(e,"package.json");if(p.existsSync(r))return e;e=o.dirname(e)}return null}a(d,"findPackageRoot");const m=d(u);function k(){var e,r;let t=!1;for(const n of g(k)){const i=S((e=n==null?void 0:n.getFileName)==null?void 0:e.call(n));if(!i||(r=i.startsWith)!=null&&r.call(i,"node:internal")||i===u)continue;let s=!1;if(m&&i.startsWith(m+o.sep)){const[c]=o.relative(m,i).split(o.sep);s=c==="src"||c==="dist"}if(t&&!s)return i;t=s}return null}a(k,"pickPrimaryBaseFile");function h(){var t,e;for(const r of g(h)){const n=S((t=r==null?void 0:r.getFileName)==null?void 0:t.call(r));if(n&&!((e=n.startsWith)!=null&&e.call(n,"node:internal"))&&n!==u)return n}return u}a(h,"pickFallbackBaseFile");function y(t,e,r,n){if(typeof t!="string")throw new TypeError("rel must be a string");const i=k()??h(),s=e(i,t);if(r(s))return s;const c=h();return n(c,t)}a(y,"resolveWith");function x(t){var e;return(e=t.startsWith)!=null&&e.call(t,"file://")?f(t):o.isAbsolute(t)?t:y(t,(r,n)=>o.resolve(o.dirname(r),n),r=>p.existsSync(r),(r,n)=>o.resolve(o.dirname(r),n))}a(x,"resolvePathFromCaller");function w(t){var e;return(e=t.startsWith)!=null&&e.call(t,"file://")?t:o.isAbsolute(t)?l(t).href:y(t,(r,n)=>new URL(n,l(r)).href,r=>p.existsSync(f(r)),(r,n)=>new URL(n,l(r)).href)}a(w,"resolveUrlFromCaller");export{g as getStack,x as resolvePathFromCaller,w as resolveUrlFromCaller,S as toFsPath};
|
|
2
|
+
//# sourceMappingURL=resolve-from-caller.mjs.map
|
package/dist/wisp.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var S=Object.defineProperty;var u=(e,l)=>S(e,"name",{value:l,configurable:!0});import U from"node:fs";import{readFile as b}from"node:fs/promises";import p from"node:path";import{pathToFileURL as h}from"node:url";import{resolveUrlFromCaller as m}from"./lib/resolve-from-caller.mjs";function d(e){return typeof globalThis.structuredClone=="function"?globalThis.structuredClone(e):JSON.parse(JSON.stringify(e))}u(d,"deepClone");function L(e,l,n){const t=e.default??e;if(!l&&!n)return t;const f=t===e?{...e}:t;return l?JSON.parse(JSON.stringify(f),l):d(f)}u(L,"moduleValue");function w(e,l,n){if(e)try{e(l)}catch(t){throw new Error(`@cldmv/wisp: Failed to load JSON file at ${n.href}: @cldmv/wisp: ${(t==null?void 0:t.message)??t}`,{cause:t})}}u(w,"runValidate");async function y(e,l={}){const{base:n,validate:t,reviver:f,type:c="json",fallback:i}=l;let r;if(e instanceof URL)r=e;else{const a=String(e);a.startsWith("file://")?r=new URL(a):p.isAbsolute(a)?r=h(a):n?r=new URL(a,new URL(n)):r=new URL(m(a))}const s=u(async a=>L(await import(r.href,a),f,t),"loadWith");for(const a of[{with:{type:c}},{assert:{type:c}}]){let o;try{o=await s(a)}catch{continue}return w(t,o,r),o}if(c==="json"){let a;try{const o=await b(r,"utf8");a=d(JSON.parse(o,f))}catch(o){if(i)return y(i,{...l,fallback:void 0});throw new Error(`@cldmv/wisp: Failed to load JSON file at ${r.href}: ${o.message}`,{cause:o})}return w(t,a,r),a}throw new Error(`@cldmv/wisp: Unsupported type '${c}' or failed to load module at ${r.href}`)}u(y,"wisp");function R(e,l={}){const{base:n,validate:t,reviver:f,fallback:c}=l;let i;if(e instanceof URL)i=e;else{const s=String(e);s.startsWith("file://")?i=new URL(s):p.isAbsolute(s)?i=h(s):n?i=new URL(s,new URL(n)):i=new URL(m(s))}let r;try{const s=U.readFileSync(i,"utf8");r=d(JSON.parse(s,f))}catch(s){if(c)return R(c,{...l,fallback:void 0});throw new Error(`@cldmv/wisp: Failed to load JSON file at ${i.href}: ${s.message}`,{cause:s})}return w(t,r,i),r}u(R,"wispSync");var F=y;export{F as default,y as wisp,R as wispSync};
|
|
2
|
+
//# sourceMappingURL=wisp.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/wisp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Version-agnostic JSON importing for Node.js with fallback handling and caller path resolution.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -19,15 +19,16 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "
|
|
22
|
+
"build": "node scripts/build.mjs",
|
|
23
23
|
"build:ci": "npm run lint && npm run format:check && npm run types:build && npm run build && npm run test && npm run test:types",
|
|
24
24
|
"prepack": "npm run types:build && npm run build",
|
|
25
25
|
"prepare": "node -e \"import('./.githooks/install.mjs').catch(()=>{})\"",
|
|
26
|
-
"test": "node tests/run-vitest.mjs && npm run test:cjs",
|
|
27
|
-
"test:cjs": "npm run build && node --conditions=wisp-dev --test tests/cjs/entry.test.cjs tests/
|
|
26
|
+
"test": "node tests/run-vitest.mjs && npm run test:cjs && npm run test:dist",
|
|
27
|
+
"test:cjs": "npm run build && node --conditions=wisp-dev --test tests/cjs/entry.test.cjs tests/built/caller-resolution.test.mjs",
|
|
28
|
+
"test:dist": "npm run build && node tests/run-vitest.mjs --mode=dist",
|
|
28
29
|
"test:watch": "vitest --config .configs/vitest.config.mjs",
|
|
29
30
|
"coverage": "node tests/run-vitest.mjs --coverage-quiet && npm run test:cjs",
|
|
30
|
-
"ci:coverage": "npm run coverage",
|
|
31
|
+
"ci:coverage": "npm run coverage && npm run test:dist",
|
|
31
32
|
"types:build": "tsc",
|
|
32
33
|
"types:check": "tsc --noEmit",
|
|
33
34
|
"test:types": "npm run types:check",
|
|
@@ -82,22 +83,22 @@
|
|
|
82
83
|
"LICENSE"
|
|
83
84
|
],
|
|
84
85
|
"devDependencies": {
|
|
85
|
-
"@cldmv/configs": "^1.
|
|
86
|
+
"@cldmv/configs": "^1.5.0",
|
|
86
87
|
"@cldmv/eslint-plugin-jsonv": "^1.0.17",
|
|
87
|
-
"@cldmv/fix-headers": "^2.
|
|
88
|
-
"@cldmv/jsonv": "^1.
|
|
89
|
-
"@cldmv/prettier-plugin-jsonv": "^1.
|
|
90
|
-
"@cldmv/vitest-runner": "^1.
|
|
88
|
+
"@cldmv/fix-headers": "^2.6.1",
|
|
89
|
+
"@cldmv/jsonv": "^1.2.4",
|
|
90
|
+
"@cldmv/prettier-plugin-jsonv": "^1.2.4",
|
|
91
|
+
"@cldmv/vitest-runner": "^1.11.4",
|
|
91
92
|
"@eslint/css": "^2.0.1",
|
|
92
93
|
"@eslint/js": "^10.0.1",
|
|
93
94
|
"@eslint/json": "^2.1.1",
|
|
94
95
|
"@eslint/markdown": "^8.0.3",
|
|
95
96
|
"@types/node": "^26.6.6",
|
|
96
97
|
"@vitest/coverage-v8": "^5.0.5",
|
|
98
|
+
"esbuild": "^0.28.2",
|
|
97
99
|
"eslint": "^10.14.0",
|
|
98
100
|
"globals": "^17.14.0",
|
|
99
101
|
"prettier": "^3.9.10",
|
|
100
|
-
"tsup": "^9.0.0",
|
|
101
102
|
"typescript": "^6.0.3",
|
|
102
103
|
"vitest": "^5.0.5"
|
|
103
104
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-from-caller.d.mts","sourceRoot":"","sources":["../../src/lib/resolve-from-caller.mjs"],"names":[],"mappings":"AAuFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,6CAhCa,KAAK,CAAC,QAAQ,CAAC,CA0C3B;
|
|
1
|
+
{"version":3,"file":"resolve-from-caller.d.mts","sourceRoot":"","sources":["../../src/lib/resolve-from-caller.mjs"],"names":[],"mappings":"AAuFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,6CAhCa,KAAK,CAAC,QAAQ,CAAC,CA0C3B;AA8KD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,2CAzCW,MAAM,GACJ,MAAM,CAsDlB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,0CA1CW,MAAM,GACJ,MAAM,CAuDlB;AAxVM,4BAvBI,GAAG,GACD,MAAM,GAAC,IAAI,CAsB+F;;iBA4VzG,MAAY,MAAM,GAAC,SAAS;mBAC5B,MAAY,MAAM,GAAC,SAAS;qBAC5B,MAAY,MAAM,GAAC,SAAS;iBAC5B,MAAY,MAAM,GAAC,SAAS;mBAC5B,MAAY,MAAM,GAAC,SAAS;8BAC5B,MAAY,MAAM,GAAC,SAAS;qBAC5B,MAAY,MAAM,GAAC,SAAS;cAC5B,MAAY,OAAO,GAAC,SAAS;YAC7B,MAAY,OAAO,GAAC,SAAS;mBAC7B,MAAY,OAAO,GAAC,SAAS;gBAC7B,MAAY,OAAO,GAAC,SAAS;aAC7B,MAAY,OAAO,GAAC,SAAS;kBAC7B,MAAY,OAAO,GAAC,SAAS;qBAC7B,MAAY,MAAM,GAAC,SAAS"}
|