tshy 1.3.0 → 1.4.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 +78 -0
- package/dist/esm/build-commonjs.d.ts.map +1 -1
- package/dist/esm/build-commonjs.js +25 -17
- package/dist/esm/build-commonjs.js.map +1 -1
- package/dist/esm/build-esm.d.ts.map +1 -1
- package/dist/esm/build-esm.js +27 -9
- package/dist/esm/build-esm.js.map +1 -1
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js +4 -2
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/exports.d.ts +7 -6
- package/dist/esm/exports.d.ts.map +1 -1
- package/dist/esm/exports.js +42 -24
- package/dist/esm/exports.js.map +1 -1
- package/dist/esm/polyfills.d.ts +9 -2
- package/dist/esm/polyfills.d.ts.map +1 -1
- package/dist/esm/polyfills.js +45 -12
- package/dist/esm/polyfills.js.map +1 -1
- package/dist/esm/resolve-export.d.ts +1 -1
- package/dist/esm/resolve-export.d.ts.map +1 -1
- package/dist/esm/resolve-export.js.map +1 -1
- package/dist/esm/tsconfig.js +55 -16
- package/dist/esm/tsconfig.js.map +1 -1
- package/dist/esm/types.d.ts +5 -33
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/valid-exports.d.ts +1 -1
- package/dist/esm/valid-exports.js +2 -2
- package/dist/esm/valid-exports.js.map +1 -1
- package/dist/esm/valid-external-export.d.ts +2 -2
- package/dist/esm/valid-external-export.d.ts.map +1 -1
- package/dist/esm/valid-external-export.js.map +1 -1
- package/dist/esm/valid-extra-dialects.d.ts +4 -0
- package/dist/esm/valid-extra-dialects.d.ts.map +1 -0
- package/dist/esm/valid-extra-dialects.js +51 -0
- package/dist/esm/valid-extra-dialects.js.map +1 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -267,6 +267,84 @@ esm, use the "Dialect Switching" trick, with the ESM code living
|
|
|
267
267
|
in `src/<whatever>.ts` and the CommonJS polyfill living in
|
|
268
268
|
`src/<whatever>-cjs.cts`.
|
|
269
269
|
|
|
270
|
+
## Other Targets: `browser`, `deno`, etc.
|
|
271
|
+
|
|
272
|
+
If you have any other dialects that you'd like to support, you
|
|
273
|
+
can list them as either `commonjsDialects` or `esmDialects`,
|
|
274
|
+
depending on whether you want them to be built as CommonJS or
|
|
275
|
+
ESM.
|
|
276
|
+
|
|
277
|
+
Note that each added dialect you create will result in another
|
|
278
|
+
build in the `./dist` folder, so you may wish to use sparingly if
|
|
279
|
+
shipping a large project.
|
|
280
|
+
|
|
281
|
+
For example:
|
|
282
|
+
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"tshy": {
|
|
286
|
+
"exports": {
|
|
287
|
+
".": "./src/index.ts"
|
|
288
|
+
},
|
|
289
|
+
"esmDialects": ["deno", "browser"],
|
|
290
|
+
"commonjsDialects": ["webpack"]
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Will result in:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"exports": {
|
|
300
|
+
".": {
|
|
301
|
+
"deno": {
|
|
302
|
+
"types": "./dist/deno/index.d.ts",
|
|
303
|
+
"default": "./dist/deno/index.js"
|
|
304
|
+
},
|
|
305
|
+
"browser": {
|
|
306
|
+
"types": "./dist/browser/index.d.ts",
|
|
307
|
+
"default": "./dist/browser/index.js"
|
|
308
|
+
},
|
|
309
|
+
"webpack": {
|
|
310
|
+
"types": "./dist/webpack/index.d.ts",
|
|
311
|
+
"default": "./dist/webpack/index.js"
|
|
312
|
+
},
|
|
313
|
+
"require": {
|
|
314
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
315
|
+
"default": "./dist/commonjs/index.js"
|
|
316
|
+
},
|
|
317
|
+
"import": {
|
|
318
|
+
"types": "./dist/esm/index.d.ts",
|
|
319
|
+
"default": "./dist/esm/index.js"
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
In each of these, you can use the same kind of dialect override
|
|
327
|
+
that works for CommonJS polyfills described above. For
|
|
328
|
+
`commonjsDialects` types, create a file named
|
|
329
|
+
`<filename>-<dialect>.cts`, and for `esmDialects` types, create a
|
|
330
|
+
file named `<filename>-<dialect>.mts`.
|
|
331
|
+
|
|
332
|
+
For example, to provide deno, browser, and webpack overrides in
|
|
333
|
+
the setup above, the following files would be relevant:
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
src/index.ts # normal esm/cjs version
|
|
337
|
+
src/index-cjs.cts # cjs variant for default commonjs
|
|
338
|
+
src/index-browser.mts # esm variant for the browser
|
|
339
|
+
src/index-deno.mts # esm variant for deno
|
|
340
|
+
src/index-webpack.cts # cjs variant for webpack
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Note that the `commonjs` override uses the abbreviated `cjs`
|
|
344
|
+
name (historical reasons, it was originally the only override
|
|
345
|
+
supported), and that the file extension must be `cts` or `mts`
|
|
346
|
+
depending on the dialect type that it is.
|
|
347
|
+
|
|
270
348
|
## Atomic Builds
|
|
271
349
|
|
|
272
350
|
Code is built in `./.tshy-build-tmp` and then copied over only if
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-commonjs.d.ts","sourceRoot":"","sources":["../../src/build-commonjs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-commonjs.d.ts","sourceRoot":"","sources":["../../src/build-commonjs.ts"],"names":[],"mappings":"AASA,OAAO,eAAe,CAAA;AAGtB,eAAO,MAAM,aAAa,iBA+BzB,CAAA"}
|
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { renameSync } from 'node:fs';
|
|
3
|
+
import { renameSync, unlinkSync } from 'node:fs';
|
|
4
4
|
import { relative, resolve } from 'node:path/posix';
|
|
5
5
|
import buildFail from './build-fail.js';
|
|
6
|
+
import config from './config.js';
|
|
6
7
|
import * as console from './console.js';
|
|
7
8
|
import polyfills from './polyfills.js';
|
|
8
9
|
import setFolderDialect from './set-folder-dialect.js';
|
|
9
10
|
import './tsconfig.js';
|
|
11
|
+
const { commonjsDialects = [] } = config;
|
|
10
12
|
export const buildCommonJS = () => {
|
|
11
|
-
console.debug(chalk.cyan.dim('building commonjs'));
|
|
12
13
|
setFolderDialect('src', 'commonjs');
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
for (const d of ['commonjs', ...commonjsDialects]) {
|
|
15
|
+
const pf = polyfills.get(d === 'commonjs' ? 'cjs' : d);
|
|
16
|
+
console.debug(chalk.cyan.dim('building ' + d));
|
|
17
|
+
const res = spawnSync(`tsc -p .tshy/${d}.json`, {
|
|
18
|
+
shell: true,
|
|
19
|
+
stdio: 'inherit',
|
|
20
|
+
});
|
|
21
|
+
if (res.status || res.signal) {
|
|
22
|
+
setFolderDialect('src');
|
|
23
|
+
return buildFail(res);
|
|
24
|
+
}
|
|
25
|
+
setFolderDialect('.tshy-build-tmp/' + d, 'commonjs');
|
|
26
|
+
for (const [override, orig] of pf?.map.entries() ?? []) {
|
|
27
|
+
const stemFrom = resolve(`.tshy-build-tmp/${d}`, relative(resolve('src'), resolve(override))).replace(/\.cts$/, '');
|
|
28
|
+
const stemTo = resolve(`.tshy-build-tmp/${d}`, relative(resolve('src'), resolve(orig))).replace(/\.tsx?$/, '');
|
|
29
|
+
unlinkSync(`${stemTo}.js.map`);
|
|
30
|
+
unlinkSync(`${stemTo}.d.ts.map`);
|
|
31
|
+
renameSync(`${stemFrom}.cjs`, `${stemTo}.js`);
|
|
32
|
+
renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`);
|
|
33
|
+
}
|
|
34
|
+
console.error(chalk.cyan.bold('built commonjs'));
|
|
28
35
|
}
|
|
36
|
+
setFolderDialect('src');
|
|
29
37
|
};
|
|
30
38
|
//# sourceMappingURL=build-commonjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-commonjs.js","sourceRoot":"","sources":["../../src/build-commonjs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"build-commonjs.js","sourceRoot":"","sources":["../../src/build-commonjs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;AACtB,MAAM,EAAE,gBAAgB,GAAG,EAAE,EAAE,GAAG,MAAM,CAAA;AAExC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IACnC,KAAK,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,gBAAgB,CAAC,EAAE;QACjD,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK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,OAAO,CAAC,CAAA;SAClD;QACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAA;KACjD;IACD,gBAAgB,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync } from 'node:child_process'\nimport { renameSync, unlinkSync } from 'node:fs'\nimport { relative, resolve } from 'node:path/posix'\nimport buildFail from './build-fail.js'\nimport config from './config.js'\nimport * as console from './console.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\nconst { commonjsDialects = [] } = config\n\nexport const buildCommonJS = () => {\n setFolderDialect('src', 'commonjs')\n for (const d of ['commonjs', ...commonjsDialects]) {\n const pf = polyfills.get(d === 'commonjs' ? 'cjs' : d)\n console.debug(chalk.cyan.dim('building ' + d))\n const res = spawnSync(`tsc -p .tshy/${d}.json`, {\n shell: true,\n stdio: 'inherit',\n })\n if (res.status || res.signal) {\n setFolderDialect('src')\n return buildFail(res)\n }\n setFolderDialect('.tshy-build-tmp/' + d, 'commonjs')\n for (const [override, orig] of pf?.map.entries() ?? []) {\n const stemFrom = resolve(\n `.tshy-build-tmp/${d}`,\n relative(resolve('src'), resolve(override))\n ).replace(/\\.cts$/, '')\n const stemTo = resolve(\n `.tshy-build-tmp/${d}`,\n relative(resolve('src'), resolve(orig))\n ).replace(/\\.tsx?$/, '')\n unlinkSync(`${stemTo}.js.map`)\n unlinkSync(`${stemTo}.d.ts.map`)\n renameSync(`${stemFrom}.cjs`, `${stemTo}.js`)\n renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`)\n }\n console.error(chalk.cyan.bold('built commonjs'))\n }\n setFolderDialect('src')\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-esm.d.ts","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-esm.d.ts","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"AASA,OAAO,eAAe,CAAA;AAGtB,eAAO,MAAM,QAAQ,iBA+BpB,CAAA"}
|
package/dist/esm/build-esm.js
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { renameSync, unlinkSync } from 'node:fs';
|
|
4
|
+
import { relative, resolve } from 'node:path';
|
|
3
5
|
import buildFail from './build-fail.js';
|
|
6
|
+
import config from './config.js';
|
|
4
7
|
import * as console from './console.js';
|
|
8
|
+
import polyfills from './polyfills.js';
|
|
5
9
|
import setFolderDialect from './set-folder-dialect.js';
|
|
6
10
|
import './tsconfig.js';
|
|
11
|
+
const { esmDialects = [] } = config;
|
|
7
12
|
export const buildESM = () => {
|
|
8
|
-
console.debug(chalk.cyan.dim('building esm'));
|
|
9
13
|
setFolderDialect('src', 'esm');
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
for (const d of ['esm', ...esmDialects]) {
|
|
15
|
+
const pf = polyfills.get(d);
|
|
16
|
+
console.debug(chalk.cyan.dim('building ' + d));
|
|
17
|
+
const res = spawnSync(`tsc -p .tshy/${d}.json`, {
|
|
18
|
+
shell: true,
|
|
19
|
+
stdio: 'inherit',
|
|
20
|
+
});
|
|
21
|
+
if (res.status || res.signal) {
|
|
22
|
+
setFolderDialect('src');
|
|
23
|
+
return buildFail(res);
|
|
24
|
+
}
|
|
25
|
+
setFolderDialect('.tshy-build-tmp/' + d, 'esm');
|
|
26
|
+
for (const [override, orig] of pf?.map.entries() ?? []) {
|
|
27
|
+
const stemFrom = resolve(`.tshy-build-tmp/${d}`, relative(resolve('src'), resolve(override))).replace(/\.mts$/, '');
|
|
28
|
+
const stemTo = resolve(`.tshy-build-tmp/${d}`, relative(resolve('src'), resolve(orig))).replace(/\.tsx?$/, '');
|
|
29
|
+
unlinkSync(`${stemTo}.js.map`);
|
|
30
|
+
unlinkSync(`${stemTo}.d.ts.map`);
|
|
31
|
+
renameSync(`${stemFrom}.mjs`, `${stemTo}.js`);
|
|
32
|
+
renameSync(`${stemFrom}.d.mts`, `${stemTo}.d.ts`);
|
|
33
|
+
}
|
|
34
|
+
console.error(chalk.cyan.bold('built ' + d));
|
|
35
|
+
}
|
|
14
36
|
setFolderDialect('src');
|
|
15
|
-
if (res.status || res.signal)
|
|
16
|
-
return buildFail(res);
|
|
17
|
-
setFolderDialect('.tshy-build-tmp/esm', 'esm');
|
|
18
|
-
console.error(chalk.cyan.bold('built esm'));
|
|
19
37
|
};
|
|
20
38
|
//# sourceMappingURL=build-esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-esm.js","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"build-esm.js","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO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AC,CAAC,CACxC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;YACxB,UAAU,CAAC,GAAG,MAAM,SAAS,CAAC,CAAA;YAC9B,UAAU,CAAC,GAAG,MAAM,WAAW,CAAC,CAAA;YAChC,UAAU,CAAC,GAAG,QAAQ,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,CAAA;YAC7C,UAAU,CAAC,GAAG,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,CAAC,CAAA;SAClD;QACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAA;KAC7C;IACD,gBAAgB,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync } from 'node:child_process'\nimport { renameSync, unlinkSync } from 'node:fs'\nimport { relative, resolve } from 'node:path'\nimport buildFail from './build-fail.js'\nimport config from './config.js'\nimport * as console from './console.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\nconst { esmDialects = [] } = config\n\nexport const buildESM = () => {\n setFolderDialect('src', 'esm')\n for (const d of ['esm', ...esmDialects]) {\n const pf = polyfills.get(d)\n console.debug(chalk.cyan.dim('building ' + d))\n const res = spawnSync(`tsc -p .tshy/${d}.json`, {\n shell: true,\n stdio: 'inherit',\n })\n if (res.status || res.signal) {\n setFolderDialect('src')\n return buildFail(res)\n }\n setFolderDialect('.tshy-build-tmp/' + d, 'esm')\n for (const [override, orig] of pf?.map.entries() ?? []) {\n const stemFrom = resolve(\n `.tshy-build-tmp/${d}`,\n relative(resolve('src'), resolve(override))\n ).replace(/\\.mts$/, '')\n const stemTo = resolve(\n `.tshy-build-tmp/${d}`,\n relative(resolve('src'), resolve(orig))\n ).replace(/\\.tsx?$/, '')\n unlinkSync(`${stemTo}.js.map`)\n unlinkSync(`${stemTo}.d.ts.map`)\n renameSync(`${stemFrom}.mjs`, `${stemTo}.js`)\n renameSync(`${stemFrom}.d.mts`, `${stemTo}.d.ts`)\n }\n console.error(chalk.cyan.bold('built ' + d))\n }\n setFolderDialect('src')\n}\n"]}
|
package/dist/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;AAyChD,QAAA,MAAM,MAAM,EAAE,UAAoC,CAAA;AAClD,eAAe,MAAM,CAAA"}
|
package/dist/esm/config.js
CHANGED
|
@@ -4,6 +4,7 @@ import pkg from './package.js';
|
|
|
4
4
|
import sources from './sources.js';
|
|
5
5
|
import validDialects from './valid-dialects.js';
|
|
6
6
|
import validExports from './valid-exports.js';
|
|
7
|
+
import validExtraDialects from './valid-extra-dialects.js';
|
|
7
8
|
const validBoolean = (e, name) => {
|
|
8
9
|
const v = e[name];
|
|
9
10
|
if (v === undefined || typeof v === 'boolean')
|
|
@@ -13,8 +14,9 @@ const validBoolean = (e, name) => {
|
|
|
13
14
|
};
|
|
14
15
|
const validConfig = (e) => !!e &&
|
|
15
16
|
typeof e === 'object' &&
|
|
16
|
-
(e.exports === undefined || validExports(e
|
|
17
|
-
(e.dialects === undefined || validDialects(e
|
|
17
|
+
(e.exports === undefined || validExports(e.exports)) &&
|
|
18
|
+
(e.dialects === undefined || validDialects(e.dialects)) &&
|
|
19
|
+
validExtraDialects(e) &&
|
|
18
20
|
validBoolean(e, 'selfLink') &&
|
|
19
21
|
validBoolean(e, 'main');
|
|
20
22
|
const getConfig = (pkg, sources) => {
|
package/dist/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC/C,OAAO,YAAY,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC/C,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAC7C,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAE1D,MAAM,YAAY,GAAG,CAAC,CAAsB,EAAE,IAAY,EAAE,EAAE;IAC5D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAA;IACjB,IAAI,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IAC1D,IAAI,CAAC,QAAQ,IAAI,8CAA8C,GAAG,CAAC,CAAC,CAAA;IACpE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,CAAM,EAAmB,EAAE,CAC9C,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,KAAK,QAAQ;IACrB,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACvD,kBAAkB,CAAC,CAAC,CAAC;IACrB,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC;IAC3B,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAEzB,MAAM,SAAS,GAAG,CAChB,GAAY,EACZ,OAAoB,EACR,EAAE;IACd,MAAM,IAAI,GAAe,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9D,IAAI,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAC7B,MAAM,CAAC,GAA8C;QACnD,gBAAgB,EAAE,gBAAgB;KACnC,CAAA;IACD,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACtC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACV,MAAK;SACN;KACF;IACD,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;IACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;IAChB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,MAAM,GAAe,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAClD,eAAe,MAAM,CAAA","sourcesContent":["// get the config and package and stuff\n\nimport fail from './fail.js'\nimport pkg from './package.js'\nimport sources from './sources.js'\nimport { Package, TshyConfig } from './types.js'\nimport validDialects from './valid-dialects.js'\nimport validExports from './valid-exports.js'\nimport validExtraDialects from './valid-extra-dialects.js'\n\nconst validBoolean = (e: Record<string, any>, name: string) => {\n const v = e[name]\n if (v === undefined || typeof v === 'boolean') return true\n fail(`tshy.${name} must be a boolean value if specified, got: ` + v)\n return process.exit(1)\n}\n\nconst validConfig = (e: any): e is TshyConfig =>\n !!e &&\n typeof e === 'object' &&\n (e.exports === undefined || validExports(e.exports)) &&\n (e.dialects === undefined || validDialects(e.dialects)) &&\n validExtraDialects(e) &&\n validBoolean(e, 'selfLink') &&\n validBoolean(e, 'main')\n\nconst getConfig = (\n pkg: Package,\n sources: Set<string>\n): TshyConfig => {\n const tshy: TshyConfig = validConfig(pkg.tshy) ? pkg.tshy : {}\n if (tshy.exports) return tshy\n const e: Exclude<TshyConfig['exports'], undefined> = {\n './package.json': './package.json',\n }\n for (const i of sources) {\n if (/^\\.\\/src\\/index\\.[^\\.]+$/.test(i)) {\n e['.'] = i\n break\n }\n }\n pkg.tshy = tshy\n tshy.exports = e\n return tshy\n}\n\nconst config: TshyConfig = getConfig(pkg, sources)\nexport default config\n"]}
|
package/dist/esm/exports.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
2
|
+
import { ExportsSubpaths } from 'resolve-import';
|
|
3
|
+
import type { PolyfillSet } from './polyfills.js';
|
|
4
|
+
import { Package, TshyConfig, TshyExport } from './types.js';
|
|
5
|
+
export declare const getImpTarget: (s: string | TshyExport | undefined | null, polyfills?: Map<string, PolyfillSet>) => string | null | undefined;
|
|
6
|
+
export declare const getReqTarget: (s: string | TshyExport | undefined | null, polyfills?: Map<string, PolyfillSet>) => string | null | undefined;
|
|
6
7
|
export declare const setMain: (c: TshyConfig | undefined, pkg: Package & {
|
|
7
|
-
exports:
|
|
8
|
+
exports: ExportsSubpaths;
|
|
8
9
|
}) => undefined;
|
|
9
|
-
declare const _default:
|
|
10
|
+
declare const _default: ExportsSubpaths;
|
|
10
11
|
export default _default;
|
|
11
12
|
//# sourceMappingURL=exports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";AACA,OAAO,EAGL,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAKvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAGjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAoC5D,eAAO,MAAM,YAAY,MACpB,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,cAC9B,IAAI,MAAM,EAAE,WAAW,CAAC,8BAE+B,CAAA;AAEpE,eAAO,MAAM,YAAY,MACpB,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,cAC9B,IAAI,MAAM,EAAE,WAAW,CAAC,8BAQlC,CAAA;AAqFH,eAAO,MAAM,OAAO,MACf,UAAU,GAAG,SAAS,OACpB,OAAO,GAAG;IAAE,SAAS,eAAe,CAAA;CAAE,cAsB5C,CAAA;;AAMD,wBAA0B"}
|
package/dist/esm/exports.js
CHANGED
|
@@ -5,33 +5,27 @@ import fail from './fail.js';
|
|
|
5
5
|
import pkg from './package.js';
|
|
6
6
|
import polyfills from './polyfills.js';
|
|
7
7
|
import { resolveExport } from './resolve-export.js';
|
|
8
|
-
|
|
8
|
+
const { esmDialects = [], commonjsDialects = [] } = config;
|
|
9
|
+
const getTargetForDialectCondition = (s, dialect, condition, type, polyfills = new Map()) => {
|
|
9
10
|
if (s === undefined)
|
|
10
11
|
return undefined;
|
|
11
12
|
if (typeof s === 'string') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
// the excluded filename pattern
|
|
14
|
+
const xts = type === 'commonjs' ? '.mts' : '.cts';
|
|
15
|
+
if (s.endsWith(xts))
|
|
16
|
+
return undefined;
|
|
17
|
+
const pf = dialect === 'commonjs' ? 'cjs' : dialect;
|
|
18
|
+
return !s || !s.startsWith('./src/')
|
|
19
|
+
? s
|
|
20
|
+
: dialects.includes(type)
|
|
21
|
+
? `./dist/${dialect}/${relative(resolve('./src'), resolve(polyfills.get(pf)?.map.get(s) ?? s)).replace(/\.([mc]?)tsx?$/, '.$1js')}`
|
|
17
22
|
: undefined;
|
|
18
23
|
}
|
|
19
|
-
return resolveExport(s, [
|
|
24
|
+
return resolveExport(s, [condition]);
|
|
20
25
|
};
|
|
21
|
-
export const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (typeof s === 'string') {
|
|
25
|
-
const req = s.endsWith('.mts') ? undefined : s;
|
|
26
|
-
return !req || !req.startsWith('./src/')
|
|
27
|
-
? req
|
|
28
|
-
: dialects.includes('commonjs')
|
|
29
|
-
? `./dist/commonjs/${relative(resolve('./src'), resolve(polyfills.get(req) || req)).replace(/\.(c?)tsx?$/, '.$1js')}`
|
|
30
|
-
: undefined;
|
|
31
|
-
}
|
|
32
|
-
return getReqTarget(resolveExport(s, ['require']), polyfills);
|
|
33
|
-
};
|
|
34
|
-
export const getExports = (c, polyfills) => {
|
|
26
|
+
export const getImpTarget = (s, polyfills = new Map()) => getTargetForDialectCondition(s, 'esm', 'import', 'esm', polyfills);
|
|
27
|
+
export const getReqTarget = (s, polyfills = new Map()) => getTargetForDialectCondition(s, 'commonjs', 'require', 'commonjs', polyfills);
|
|
28
|
+
const getExports = (c) => {
|
|
35
29
|
// by this time it always exports, will get the default if missing
|
|
36
30
|
/* c8 ignore start */
|
|
37
31
|
if (!c.exports) {
|
|
@@ -42,12 +36,13 @@ export const getExports = (c, polyfills) => {
|
|
|
42
36
|
const e = {};
|
|
43
37
|
for (const [sub, s] of Object.entries(c.exports)) {
|
|
44
38
|
// external export, not built by us
|
|
45
|
-
if (
|
|
39
|
+
if (s !== null &&
|
|
40
|
+
(typeof s !== 'string' || !s.startsWith('./src/'))) {
|
|
46
41
|
// already been validated, just accept as-is
|
|
47
42
|
e[sub] = s;
|
|
48
43
|
continue;
|
|
49
44
|
}
|
|
50
|
-
const impTarget = getImpTarget(s);
|
|
45
|
+
const impTarget = getImpTarget(s, polyfills);
|
|
51
46
|
const reqTarget = getReqTarget(s, polyfills);
|
|
52
47
|
// should be impossible
|
|
53
48
|
/* c8 ignore start */
|
|
@@ -55,6 +50,29 @@ export const getExports = (c, polyfills) => {
|
|
|
55
50
|
continue;
|
|
56
51
|
/* c8 ignore stop */
|
|
57
52
|
const exp = (e[sub] = {});
|
|
53
|
+
if (impTarget) {
|
|
54
|
+
for (const d of esmDialects) {
|
|
55
|
+
const target = getTargetForDialectCondition(s, d, d, 'esm', polyfills);
|
|
56
|
+
if (target) {
|
|
57
|
+
exp[d] = {
|
|
58
|
+
types: target.replace(/\.js$/, '.d.ts'),
|
|
59
|
+
default: target,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (reqTarget) {
|
|
65
|
+
for (const d of commonjsDialects) {
|
|
66
|
+
const target = getTargetForDialectCondition(s, d, d, 'commonjs', polyfills);
|
|
67
|
+
if (target) {
|
|
68
|
+
exp[d] = {
|
|
69
|
+
types: target.replace(/\.js$/, '.d.ts'),
|
|
70
|
+
default: target,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// put the default import/require after all the other special ones.
|
|
58
76
|
if (impTarget) {
|
|
59
77
|
exp.import = {
|
|
60
78
|
types: impTarget.replace(/\.(m?)js$/, '.d.$1ts'),
|
|
@@ -98,7 +116,7 @@ export const setMain = (c, pkg) => {
|
|
|
98
116
|
};
|
|
99
117
|
// These are all defined by exports, so it's just confusing otherwise
|
|
100
118
|
delete pkg.module;
|
|
101
|
-
pkg.exports = getExports(config
|
|
119
|
+
pkg.exports = getExports(config);
|
|
102
120
|
setMain(config, pkg);
|
|
103
121
|
export default pkg.exports;
|
|
104
122
|
//# sourceMappingURL=exports.js.map
|
package/dist/esm/exports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,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\n ConditionalValue,\n ConditionalValueObject,\n ExportsSubpaths,\n} from 'resolve-import'\nimport config from './config.js'\nimport dialects from './dialects.js'\nimport fail from './fail.js'\nimport pkg from './package.js'\nimport type { PolyfillSet } from './polyfills.js'\nimport polyfills from './polyfills.js'\nimport { resolveExport } from './resolve-export.js'\nimport { Package, TshyConfig, TshyExport } from './types.js'\nconst { esmDialects = [], commonjsDialects = [] } = config\n\nconst getTargetForDialectCondition = <T extends string>(\n s: string | TshyExport | undefined | null,\n dialect: T,\n condition: T extends 'esm'\n ? 'import'\n : T extends 'commonjs'\n ? 'require'\n : T,\n type: T extends 'esm'\n ? 'esm'\n : T extends 'commonjs'\n ? 'commonjs'\n : 'esm' | 'commonjs',\n polyfills: Map<string, PolyfillSet> = new Map()\n): string | undefined | null => {\n if (s === undefined) return undefined\n if (typeof s === 'string') {\n // the excluded filename pattern\n const xts = type === 'commonjs' ? '.mts' : '.cts'\n if (s.endsWith(xts)) return undefined\n const pf = dialect === 'commonjs' ? 'cjs' : dialect\n return !s || !s.startsWith('./src/')\n ? s\n : dialects.includes(type)\n ? `./dist/${dialect}/${relative(\n resolve('./src'),\n resolve(polyfills.get(pf)?.map.get(s) ?? s)\n ).replace(/\\.([mc]?)tsx?$/, '.$1js')}`\n : undefined\n }\n return resolveExport(s, [condition])\n}\n\nexport const getImpTarget = (\n s: string | TshyExport | undefined | null,\n polyfills: Map<string, PolyfillSet> = new Map()\n) =>\n getTargetForDialectCondition(s, 'esm', 'import', 'esm', polyfills)\n\nexport const getReqTarget = (\n s: string | TshyExport | undefined | null,\n polyfills: Map<string, PolyfillSet> = new Map()\n) =>\n getTargetForDialectCondition(\n s,\n 'commonjs',\n 'require',\n 'commonjs',\n polyfills\n )\n\nconst getExports = (\n c: TshyConfig\n): Record<string, ConditionalValue> => {\n // by this time it always exports, will get the default if missing\n /* c8 ignore start */\n if (!c.exports) {\n fail('no exports on tshy config (is there code in ./src?)')\n return process.exit(1)\n }\n /* c8 ignore stop */\n const e: Record<string, ConditionalValue> = {}\n for (const [sub, s] of Object.entries(c.exports)) {\n // external export, not built by us\n if (\n s !== null &&\n (typeof s !== 'string' || !s.startsWith('./src/'))\n ) {\n // already been validated, just accept as-is\n e[sub] = s as ConditionalValue\n continue\n }\n\n const impTarget = getImpTarget(s, polyfills)\n const reqTarget = getReqTarget(s, polyfills)\n\n // should be impossible\n /* c8 ignore start */\n if (!impTarget && !reqTarget) continue\n /* c8 ignore stop */\n\n const exp: ConditionalValueObject = (e[sub] = {})\n if (impTarget) {\n for (const d of esmDialects) {\n const target = getTargetForDialectCondition(\n s,\n d,\n d,\n 'esm',\n polyfills\n )\n if (target) {\n exp[d] = {\n types: target.replace(/\\.js$/, '.d.ts'),\n default: target,\n }\n }\n }\n }\n\n if (reqTarget) {\n for (const d of commonjsDialects) {\n const target = getTargetForDialectCondition(\n s,\n d,\n d,\n 'commonjs',\n polyfills\n )\n if (target) {\n exp[d] = {\n types: target.replace(/\\.js$/, '.d.ts'),\n default: target,\n }\n }\n }\n }\n // put the default import/require after all the other special ones.\n if (impTarget) {\n exp.import = {\n types: impTarget.replace(/\\.(m?)js$/, '.d.$1ts'),\n default: impTarget,\n }\n }\n if (reqTarget) {\n exp.require = {\n types: reqTarget.replace(/\\.(c?)js$/, '.d.$1ts'),\n default: reqTarget,\n }\n }\n }\n return e\n}\n\nexport const setMain = (\n c: TshyConfig | undefined,\n pkg: Package & { exports: ExportsSubpaths }\n) => {\n const mod = resolveExport(pkg.exports['.'], ['require'])\n const main = c?.main ?? !!mod\n if (main) {\n if (!mod) {\n fail(`could not resolve exports['.'] for tshy.main 'require'`)\n return process.exit(1)\n }\n const types = resolveExport(pkg.exports['.'], [\n 'require',\n 'types',\n ])\n pkg.main = mod\n if (types && types !== mod) pkg.types = types\n else delete pkg.types\n } else {\n if (c) delete c.main\n delete pkg.main\n delete pkg.types\n }\n pkg.type = 'module'\n}\n\n// These are all defined by exports, so it's just confusing otherwise\ndelete pkg.module\npkg.exports = getExports(config)\nsetMain(config, pkg as Package & { exports: ExportsSubpaths })\nexport default pkg.exports\n"]}
|
package/dist/esm/polyfills.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
1
|
+
export declare class PolyfillSet {
|
|
2
|
+
type: 'esm' | 'commonjs';
|
|
3
|
+
name: string;
|
|
4
|
+
map: Map<string, string>;
|
|
5
|
+
constructor(type: 'esm' | 'commonjs', name: string);
|
|
6
|
+
addFile(f: string, sources: Set<string>): void;
|
|
7
|
+
}
|
|
8
|
+
declare const polyfills: Map<string, PolyfillSet>;
|
|
9
|
+
export default polyfills;
|
|
3
10
|
//# sourceMappingURL=polyfills.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../../src/polyfills.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../../src/polyfills.ts"],"names":[],"mappings":"AAQA,qBAAa,WAAW;IACtB,IAAI,EAAE,KAAK,GAAG,UAAU,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,sBAA4B;gBACnB,IAAI,EAAE,KAAK,GAAG,UAAU,EAAE,IAAI,EAAE,MAAM;IAIlD,OAAO,CAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC;CAYzC;AAED,QAAA,MAAM,SAAS,0BAEb,CAAA;AAqBF,eAAe,SAAS,CAAA"}
|
package/dist/esm/polyfills.js
CHANGED
|
@@ -1,19 +1,52 @@
|
|
|
1
1
|
// the modules like -cjs.cts that override a module at .ts
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
3
|
+
import config from './config.js';
|
|
4
4
|
import * as console from './console.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
import sources from './sources.js';
|
|
6
|
+
const { esmDialects = [], commonjsDialects = [] } = config;
|
|
7
|
+
export class PolyfillSet {
|
|
8
|
+
type;
|
|
9
|
+
name;
|
|
10
|
+
map = new Map();
|
|
11
|
+
constructor(type, name) {
|
|
12
|
+
this.type = type;
|
|
13
|
+
this.name = name;
|
|
14
|
+
}
|
|
15
|
+
addFile(f, sources) {
|
|
16
|
+
const dotts = this.type === 'commonjs' ? 'cts' : 'mts';
|
|
17
|
+
const ending = `-${this.name}.${dotts}`;
|
|
18
|
+
if (!f.endsWith(ending))
|
|
19
|
+
return;
|
|
20
|
+
const ts = f.substring(0, f.length - ending.length) + '.ts';
|
|
21
|
+
const tsx = ts + 'x';
|
|
22
|
+
if (sources.has(ts))
|
|
23
|
+
this.map.set(f, ts);
|
|
24
|
+
else if (sources.has(tsx))
|
|
25
|
+
this.map.set(f, tsx);
|
|
26
|
+
}
|
|
27
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
28
|
+
return [this.name, this.map];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const polyfills = new Map([
|
|
32
|
+
['cjs', new PolyfillSet('commonjs', 'cjs')],
|
|
33
|
+
]);
|
|
34
|
+
for (const d of commonjsDialects)
|
|
35
|
+
polyfills.set(d, new PolyfillSet('commonjs', d));
|
|
36
|
+
for (const d of esmDialects)
|
|
37
|
+
polyfills.set(d, new PolyfillSet('esm', d));
|
|
38
|
+
for (const f of sources) {
|
|
39
|
+
for (const pf of polyfills.values()) {
|
|
40
|
+
pf.addFile(f, sources);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// delete any polyfill types that have no entries
|
|
44
|
+
for (const [name, pf] of polyfills.entries()) {
|
|
45
|
+
if (pf.map.size === 0)
|
|
46
|
+
polyfills.delete(name);
|
|
47
|
+
}
|
|
15
48
|
if (polyfills.size) {
|
|
16
49
|
console.debug(chalk.cyan.dim('polyfills detected'), polyfills);
|
|
17
50
|
}
|
|
18
|
-
export default
|
|
51
|
+
export default polyfills;
|
|
19
52
|
//# sourceMappingURL=polyfills.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfills.js","sourceRoot":"","sources":["../../src/polyfills.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,
|
|
1
|
+
{"version":3,"file":"polyfills.js","sourceRoot":"","sources":["../../src/polyfills.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,gBAAgB,GAAG,EAAE,EAAE,GAAG,MAAM,CAAA;AAE1D,MAAM,OAAO,WAAW;IACtB,IAAI,CAAoB;IACxB,IAAI,CAAQ;IACZ,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC/B,YAAY,IAAwB,EAAE,IAAY;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IACD,OAAO,CAAE,CAAS,EAAE,OAAoB;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;QACtD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,CAAA;QACvC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAM;QAC/B,MAAM,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAA;QAC3D,MAAM,GAA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CAAC,IAAI,EAAE;IAClB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAA;CAC/D;AAED,eAAe,SAAS,CAAA","sourcesContent":["// the modules like -cjs.cts that override a module at .ts\nimport chalk from 'chalk'\nimport config from './config.js'\nimport * as console from './console.js'\nimport sources from './sources.js'\n\nconst { esmDialects = [], commonjsDialects = [] } = config\n\nexport class PolyfillSet {\n type: 'esm' | 'commonjs'\n name: string\n map = new Map<string, string>()\n constructor(type: 'esm' | 'commonjs', name: string) {\n this.type = type\n this.name = name\n }\n addFile (f: string, sources: Set<string>) {\n const dotts = this.type === 'commonjs' ? 'cts' : 'mts'\n const ending = `-${this.name}.${dotts}`\n if (!f.endsWith(ending)) return\n const ts = f.substring(0, f.length - ending.length) + '.ts'\n const tsx = ts + 'x'\n if (sources.has(ts)) this.map.set(f, ts)\n else if (sources.has(tsx)) this.map.set(f, tsx)\n }\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return [this.name, this.map]\n }\n}\n\nconst polyfills = new Map<string, PolyfillSet>([\n ['cjs', new PolyfillSet('commonjs', 'cjs')],\n])\nfor (const d of commonjsDialects)\n polyfills.set(d, new PolyfillSet('commonjs', d))\nfor (const d of esmDialects)\n polyfills.set(d, new PolyfillSet('esm', d))\n\nfor (const f of sources) {\n for (const pf of polyfills.values()) {\n pf.addFile(f, sources)\n }\n}\n\n// delete any polyfill types that have no entries\nfor (const [name, pf] of polyfills.entries()) {\n if (pf.map.size === 0) polyfills.delete(name)\n}\n\nif (polyfills.size) {\n console.debug(chalk.cyan.dim('polyfills detected'), polyfills)\n}\n\nexport default polyfills\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const resolveExport: (exp: any, conditions:
|
|
1
|
+
export declare const resolveExport: (exp: any, conditions: string[]) => string | undefined | null;
|
|
2
2
|
//# sourceMappingURL=resolve-export.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-export.d.ts","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QACnB,GAAG,cACI,
|
|
1
|
+
{"version":3,"file":"resolve-export.d.ts","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QACnB,GAAG,cACI,MAAM,EAAE,KACnB,MAAM,GAAG,SAAS,GAAG,IAkBvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-export.js","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"resolve-export.js","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,UAAoB,EACO,EAAE;IAC7B,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAA;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAC7C,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,GAAG,CAAA;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;YACnB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;YACtC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;gBAAE,OAAO,CAAC,CAAA;SAC9B;QACD,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,KAAK,GAAG,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAChD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACxC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;YACrB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;YACtC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;gBAAE,OAAO,CAAC,CAAA;SAC9B;KACF;AACH,CAAC,CAAA","sourcesContent":["export const resolveExport = (\n exp: any,\n conditions: string[]\n): string | undefined | null => {\n if (typeof exp === 'string') return exp\n if (typeof exp !== 'object') return undefined\n if (exp === null) return exp\n if (Array.isArray(exp)) {\n for (const e of exp) {\n const u = resolveExport(e, conditions)\n if (u || u === null) return u\n }\n return undefined\n }\n const conds = [...conditions, 'node', 'default']\n for (const [c, e] of Object.entries(exp)) {\n if (conds.includes(c)) {\n const u = resolveExport(e, conditions)\n if (u || u === null) return u\n }\n }\n}\n"]}
|
package/dist/esm/tsconfig.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { existsSync, writeFileSync } from 'fs';
|
|
3
2
|
import { mkdirpSync } from 'mkdirp';
|
|
3
|
+
import { join } from 'node:path/posix';
|
|
4
|
+
import { existsSync, readdirSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
5
|
+
import { resolve } from 'node:path';
|
|
4
6
|
import * as console from './console.js';
|
|
5
7
|
// the commonjs build needs to exclude anything that will be polyfilled
|
|
6
8
|
import polyfills from './polyfills.js';
|
|
9
|
+
import config from './config.js';
|
|
10
|
+
const { dialects = ['esm', 'commonjs'], esmDialects = [], commonjsDialects = [], } = config;
|
|
7
11
|
const recommended = {
|
|
8
12
|
compilerOptions: {
|
|
9
13
|
declaration: true,
|
|
@@ -31,20 +35,42 @@ const build = {
|
|
|
31
35
|
moduleResolution: 'nodenext',
|
|
32
36
|
},
|
|
33
37
|
};
|
|
34
|
-
const commonjs = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const commonjs = (dialect) => {
|
|
39
|
+
const exclude = ['../src/**/*.mts'];
|
|
40
|
+
for (const [d, pf] of polyfills) {
|
|
41
|
+
if (d === dialect)
|
|
42
|
+
continue;
|
|
43
|
+
for (const f of pf.map.keys()) {
|
|
44
|
+
exclude.push(`../${join(f)}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
extends: './build.json',
|
|
49
|
+
include: ['../src/**/*.ts', '../src/**/*.cts', '../src/**/*.tsx'],
|
|
50
|
+
exclude,
|
|
51
|
+
compilerOptions: {
|
|
52
|
+
outDir: '../.tshy-build-tmp/' +
|
|
53
|
+
(dialect === 'cjs' ? 'commonjs' : dialect),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
41
56
|
};
|
|
42
|
-
const esm = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
const esm = (dialect) => {
|
|
58
|
+
const exclude = [];
|
|
59
|
+
for (const [d, pf] of polyfills) {
|
|
60
|
+
if (d === dialect)
|
|
61
|
+
continue;
|
|
62
|
+
for (const f of pf.map.keys()) {
|
|
63
|
+
exclude.push(`../${f}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
extends: './build.json',
|
|
68
|
+
include: ['../src/**/*.ts', '../src/**/*.mts', '../src/**/*.tsx'],
|
|
69
|
+
exclude,
|
|
70
|
+
compilerOptions: {
|
|
71
|
+
outDir: '../.tshy-build-tmp/' + dialect,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
48
74
|
};
|
|
49
75
|
mkdirpSync('.tshy');
|
|
50
76
|
const writeConfig = (name, data) => writeFileSync(`.tshy/${name}.json`, JSON.stringify(data, null, 2) + '\n');
|
|
@@ -53,7 +79,20 @@ if (!existsSync('tsconfig.json')) {
|
|
|
53
79
|
console.debug('using existing tsconfig.json');
|
|
54
80
|
writeConfig('../tsconfig', recommended);
|
|
55
81
|
}
|
|
82
|
+
for (const f of readdirSync('.tshy')) {
|
|
83
|
+
unlinkSync(resolve('.tshy', f));
|
|
84
|
+
}
|
|
56
85
|
writeConfig('build', build);
|
|
57
|
-
|
|
58
|
-
writeConfig('
|
|
86
|
+
if (dialects.includes('commonjs')) {
|
|
87
|
+
writeConfig('commonjs', commonjs('cjs'));
|
|
88
|
+
for (const d of commonjsDialects) {
|
|
89
|
+
writeConfig(d, commonjs(d));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (dialects.includes('esm')) {
|
|
93
|
+
writeConfig('esm', esm('esm'));
|
|
94
|
+
for (const d of esmDialects) {
|
|
95
|
+
writeConfig(d, esm(d));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
59
98
|
//# sourceMappingURL=tsconfig.js.map
|
package/dist/esm/tsconfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../src/tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../src/tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,uEAAuE;AACvE,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,MAAM,EACJ,QAAQ,GAAG,CAAC,KAAK,EAAE,UAAU,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;CAChC;AACD,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAC3B,IAAI,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;IACjC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;IACxC,KAAK,MAAM,CAAC,IAAI,gBAAgB,EAAE;QAChC,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;KAC5B;CACF;AACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;IAC5B,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9B,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE;QAC3B,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;KACvB;CACF","sourcesContent":["import chalk from 'chalk'\nimport { mkdirpSync } from 'mkdirp'\nimport { join } from 'node:path/posix'\nimport {\n existsSync,\n readdirSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs'\nimport { resolve } from 'node:path'\nimport * as console from './console.js'\n\n// the commonjs build needs to exclude anything that will be polyfilled\nimport polyfills from './polyfills.js'\n\nimport config from './config.js'\nconst {\n dialects = ['esm', 'commonjs'],\n esmDialects = [],\n commonjsDialects = [],\n} = config\n\nconst recommended: Record<string, any> = {\n compilerOptions: {\n declaration: true,\n declarationMap: true,\n esModuleInterop: true,\n forceConsistentCasingInFileNames: true,\n inlineSources: true,\n jsx: 'react',\n module: 'nodenext',\n moduleResolution: 'nodenext',\n noUncheckedIndexedAccess: true,\n resolveJsonModule: true,\n skipLibCheck: true,\n sourceMap: true,\n strict: true,\n target: 'es2022',\n },\n}\n\nconst build: Record<string, any> = {\n extends: '../tsconfig.json',\n compilerOptions: {\n rootDir: '../src',\n target: 'es2022',\n module: 'nodenext',\n moduleResolution: 'nodenext',\n },\n}\n\nconst commonjs = (dialect: string): Record<string, any> => {\n const exclude = ['../src/**/*.mts']\n for (const [d, pf] of polyfills) {\n if (d === dialect) continue\n for (const f of pf.map.keys()) {\n exclude.push(`../${join(f)}`)\n }\n }\n return {\n extends: './build.json',\n include: ['../src/**/*.ts', '../src/**/*.cts', '../src/**/*.tsx'],\n exclude,\n compilerOptions: {\n outDir:\n '../.tshy-build-tmp/' +\n (dialect === 'cjs' ? 'commonjs' : dialect),\n },\n }\n}\n\nconst esm = (dialect: string): Record<string, any> => {\n const exclude = []\n for (const [d, pf] of polyfills) {\n if (d === dialect) continue\n for (const f of pf.map.keys()) {\n exclude.push(`../${f}`)\n }\n }\n return {\n extends: './build.json',\n include: ['../src/**/*.ts', '../src/**/*.mts', '../src/**/*.tsx'],\n exclude,\n compilerOptions: {\n outDir: '../.tshy-build-tmp/' + dialect,\n },\n }\n}\n\nmkdirpSync('.tshy')\nconst writeConfig = (name: string, data: Record<string, any>) =>\n writeFileSync(\n `.tshy/${name}.json`,\n JSON.stringify(data, null, 2) + '\\n'\n )\n\nconsole.debug(chalk.cyan.dim('writing tsconfig files...'))\nif (!existsSync('tsconfig.json')) {\n console.debug('using existing tsconfig.json')\n writeConfig('../tsconfig', recommended)\n}\nfor (const f of readdirSync('.tshy')) {\n unlinkSync(resolve('.tshy', f))\n}\nwriteConfig('build', build)\nif (dialects.includes('commonjs')) {\n writeConfig('commonjs', commonjs('cjs'))\n for (const d of commonjsDialects) {\n writeConfig(d, commonjs(d))\n }\n}\nif (dialects.includes('esm')) {\n writeConfig('esm', esm('esm'))\n for (const d of esmDialects) {\n writeConfig(d, esm(d))\n }\n}\n"]}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
+
import type { ConditionalValue, ExportsSubpaths } from 'resolve-import';
|
|
1
2
|
export type TshyConfig = {
|
|
2
3
|
exports?: Record<string, TshyExport>;
|
|
3
4
|
dialects?: Dialect[];
|
|
4
5
|
selfLink?: boolean;
|
|
5
6
|
main?: boolean;
|
|
7
|
+
commonjsDialects?: string[];
|
|
8
|
+
esmDialects?: string[];
|
|
6
9
|
};
|
|
7
10
|
export type Dialect = 'commonjs' | 'esm';
|
|
8
11
|
export type ExportDetail = {
|
|
9
12
|
default: string;
|
|
10
13
|
[k: string]: string;
|
|
11
14
|
};
|
|
12
|
-
export type TshyExport =
|
|
13
|
-
types?: string;
|
|
14
|
-
import?: string;
|
|
15
|
-
require?: string;
|
|
16
|
-
} & ({
|
|
17
|
-
import: string;
|
|
18
|
-
} | {
|
|
19
|
-
require: string;
|
|
20
|
-
})) | ({
|
|
21
|
-
types?: string;
|
|
22
|
-
import?: ExportDetail;
|
|
23
|
-
require?: ExportDetail;
|
|
24
|
-
} & ({
|
|
25
|
-
import: ExportDetail;
|
|
26
|
-
} | {
|
|
27
|
-
require: ExportDetail;
|
|
28
|
-
}));
|
|
15
|
+
export type TshyExport = ConditionalValue;
|
|
29
16
|
export type Package = {
|
|
30
17
|
name: string;
|
|
31
18
|
version: string;
|
|
@@ -33,24 +20,9 @@ export type Package = {
|
|
|
33
20
|
types?: string;
|
|
34
21
|
type?: 'module';
|
|
35
22
|
bin?: string | Record<string, string>;
|
|
36
|
-
exports?:
|
|
23
|
+
exports?: ExportsSubpaths;
|
|
37
24
|
tshy?: TshyConfig;
|
|
38
25
|
imports?: Record<string, any>;
|
|
39
26
|
[k: string]: any;
|
|
40
27
|
};
|
|
41
|
-
export type Export = string | {
|
|
42
|
-
import?: Export;
|
|
43
|
-
require?: Export;
|
|
44
|
-
types?: Export;
|
|
45
|
-
default?: Export;
|
|
46
|
-
} | {
|
|
47
|
-
import?: string | {
|
|
48
|
-
types: string;
|
|
49
|
-
default: string;
|
|
50
|
-
};
|
|
51
|
-
require?: string | {
|
|
52
|
-
types: string;
|
|
53
|
-
default: string;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
28
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACpC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEvE,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACpC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,KAAK,CAAA;AAExC,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAA;AAEzC,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB,CAAA"}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ConditionalValue, ExportsSubpaths } from 'resolve-import'\n\nexport type TshyConfig = {\n exports?: Record<string, TshyExport>\n dialects?: Dialect[]\n selfLink?: boolean\n main?: boolean\n commonjsDialects?: string[]\n esmDialects?: string[]\n}\n\nexport type Dialect = 'commonjs' | 'esm'\n\nexport type ExportDetail = {\n default: string\n [k: string]: string\n}\n\nexport type TshyExport = ConditionalValue\n\nexport type Package = {\n name: string\n version: string\n main?: string\n types?: string\n type?: 'module'\n bin?: string | Record<string, string>\n exports?: ExportsSubpaths\n tshy?: TshyConfig\n imports?: Record<string, any>\n [k: string]: any\n}\n"]}
|
|
@@ -15,8 +15,8 @@ export default (e) => {
|
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
17
|
if (typeof exp !== 'object') {
|
|
18
|
-
fail(`tshy.exports ${sub} value must be valid package.json exports
|
|
19
|
-
`got: ${JSON.stringify(exp)}`);
|
|
18
|
+
fail(`tshy.exports ${sub} value must be valid package.json exports ` +
|
|
19
|
+
`value, got: ${JSON.stringify(exp)}`);
|
|
20
20
|
return process.exit(1);
|
|
21
21
|
}
|
|
22
22
|
// can be any valid external export, but the resolution of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-exports.js","sourceRoot":"","sources":["../../src/valid-exports.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cA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AG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACxC,IAAI,CACF,yDAAyD,GAAG,EAAE,CAC/D,CAAA;YACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SACvB;QAED,mEAAmE;QACnE,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;YACpB,SAAQ;SACT;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAI,CACF,gBAAgB,GAAG,4CAA4C;gBAC7D,eAAe,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CACvC,CAAA;YACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SACvB;QAED,0DAA0D;QAC1D,0CAA0C;QAC1C,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE;YAC7B,IAAI,CACF,gBAAgB,GAAG,yCAAyC;gBAC1D,4CAA4C;gBAC5C,QAAQ,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAChC,CAAA;YACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SACvB;QAED,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;KACb;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import addDot from './add-dot.js'\nimport fail from './fail.js'\nimport { TshyConfig } from './types.js'\nimport validExternalExport from './valid-external-export.js'\n\nexport default (\n e: any\n): e is Exclude<TshyConfig['exports'], undefined> => {\n if (!e || typeof e !== 'object' || Array.isArray(e)) return false\n for (const [sub, exp] of Object.entries(e)) {\n if (sub !== '.' && !sub.startsWith('./')) {\n fail(\n `tshy.exports key must be \".\" or start with \"./\", got: ${sub}`\n )\n return process.exit(1)\n }\n\n // just a module. either a built export, or a simple unbuilt export\n if (typeof exp === 'string') {\n e[sub] = addDot(exp)\n continue\n }\n\n if (typeof exp !== 'object') {\n fail(\n `tshy.exports ${sub} value must be valid package.json exports ` +\n `value, got: ${JSON.stringify(exp)}`\n )\n return process.exit(1)\n }\n\n // can be any valid external export, but the resolution of\n // import and require must NOT be in ./src\n if (!validExternalExport(exp)) {\n fail(\n `tshy.exports ${sub} unbuilt exports must not be in ./src, ` +\n `and exports in src must be string values. ` +\n `got: ${JSON.stringify(exp)}`\n )\n return process.exit(1)\n }\n\n e[sub] = exp\n }\n return true\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const _default: (exp: any) => exp is
|
|
1
|
+
import type { ConditionalValueObject } from 'resolve-import';
|
|
2
|
+
declare const _default: (exp: any) => exp is ConditionalValueObject;
|
|
3
3
|
export default _default;
|
|
4
4
|
//# sourceMappingURL=valid-external-export.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-external-export.d.ts","sourceRoot":"","sources":["../../src/valid-external-export.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"valid-external-export.d.ts","sourceRoot":"","sources":["../../src/valid-external-export.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;8BAGvC,GAAG;AAAxB,wBAMC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-external-export.js","sourceRoot":"","sources":["../../src/valid-external-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"valid-external-export.js","sourceRoot":"","sources":["../../src/valid-external-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,eAAe,CAAC,GAAQ,EAAiC,EAAE;IACzD,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IACxC,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IACzC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IACjD,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IACjD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { join } from 'path/posix'\nimport type { ConditionalValueObject } from 'resolve-import'\nimport { resolveExport } from './resolve-export.js'\n\nexport default (exp: any): exp is ConditionalValueObject => {\n const i = resolveExport(exp, ['import'])\n const r = resolveExport(exp, ['require'])\n if (i && join(i).startsWith('src/')) return false\n if (r && join(r).startsWith('src/')) return false\n return true\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-extra-dialects.d.ts","sourceRoot":"","sources":["../../src/valid-extra-dialects.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;4DAwCY,UAAU;AAA7D,wBAsBC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// validate esmDialects and commonjsDialects
|
|
2
|
+
import fail from './fail.js';
|
|
3
|
+
const arrayOverlap = (a, b) => {
|
|
4
|
+
if (!a || !b)
|
|
5
|
+
return false;
|
|
6
|
+
for (const av of a) {
|
|
7
|
+
if (b.includes(av)) {
|
|
8
|
+
return av;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
const validExtraDialectSet = (e, which) => {
|
|
14
|
+
for (const d of e) {
|
|
15
|
+
if (typeof d !== 'string') {
|
|
16
|
+
fail(`${which} must be an array of strings, got: ${d}`);
|
|
17
|
+
return process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
if (d === 'commonjs' ||
|
|
20
|
+
d === 'cjs' ||
|
|
21
|
+
d === 'esm' ||
|
|
22
|
+
d === 'require' ||
|
|
23
|
+
d === 'import' ||
|
|
24
|
+
d === 'node' ||
|
|
25
|
+
d === 'default') {
|
|
26
|
+
fail(`${which} must not contain ${d}`);
|
|
27
|
+
return process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
export default ({ commonjsDialects, esmDialects }) => {
|
|
33
|
+
if (commonjsDialects === undefined && esmDialects === undefined) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (commonjsDialects &&
|
|
37
|
+
!validExtraDialectSet(commonjsDialects, 'commonjs')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (esmDialects && !validExtraDialectSet(esmDialects, 'esm')) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const overlap = arrayOverlap(commonjsDialects, esmDialects);
|
|
44
|
+
if (overlap) {
|
|
45
|
+
fail('commonjsDialects and esmDialects must be unique, ' +
|
|
46
|
+
`found ${overlap} in both lists`);
|
|
47
|
+
return process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=valid-extra-dialects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-extra-dialects.js","sourceRoot":"","sources":["../../src/valid-extra-dialects.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,MAAM,YAAY,GAAG,CACnB,CAAuB,EACvB,CAAuB,EACP,EAAE;IAClB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAC1B,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE;QAClB,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EA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I,CAAC,CAAC,CAAC,CAAA;KACvB;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["// validate esmDialects and commonjsDialects\nimport fail from './fail.js'\nimport { TshyConfig } from './types.js'\n\nconst arrayOverlap = (\n a: string[] | undefined,\n b: string[] | undefined\n): string | false => {\n if (!a || !b) return false\n for (const av of a) {\n if (b.includes(av)) {\n return av\n }\n }\n return false\n}\n\nconst validExtraDialectSet = (\n e: string[],\n which: 'commonjs' | 'esm'\n) => {\n for (const d of e) {\n if (typeof d !== 'string') {\n fail(`${which} must be an array of strings, got: ${d}`)\n return process.exit(1)\n }\n if (\n d === 'commonjs' ||\n d === 'cjs' ||\n d === 'esm' ||\n d === 'require' ||\n d === 'import' ||\n d === 'node' ||\n d === 'default'\n ) {\n fail(`${which} must not contain ${d}`)\n return process.exit(1)\n }\n }\n return true\n}\n\nexport default ({ commonjsDialects, esmDialects }: TshyConfig) => {\n if (commonjsDialects === undefined && esmDialects === undefined) {\n return true\n }\n if (\n commonjsDialects &&\n !validExtraDialectSet(commonjsDialects, 'commonjs')\n ) {\n return false\n }\n if (esmDialects && !validExtraDialectSet(esmDialects, 'esm')) {\n return false\n }\n const overlap = arrayOverlap(commonjsDialects, esmDialects)\n if (overlap) {\n fail(\n 'commonjsDialects and esmDialects must be unique, ' +\n `found ${overlap} in both lists`\n )\n return process.exit(1)\n }\n return true\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tshy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "TypeScript HYbridizer - Hybrid (CommonJS/ESM) TypeScript node package builder",
|
|
5
5
|
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
|
|
6
6
|
"license": "BlueOak-1.0.0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"chalk": "^5.3.0",
|
|
14
14
|
"foreground-child": "^3.1.1",
|
|
15
15
|
"mkdirp": "^3.0.1",
|
|
16
|
-
"resolve-import": "^1.4.
|
|
16
|
+
"resolve-import": "^1.4.4",
|
|
17
17
|
"rimraf": "^5.0.1",
|
|
18
18
|
"sync-content": "^1.0.2",
|
|
19
19
|
"typescript": "5.2",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"snap": "tap"
|
|
32
32
|
},
|
|
33
33
|
"tap": {
|
|
34
|
-
"coverage-map": "map.js"
|
|
34
|
+
"coverage-map": "map.js",
|
|
35
|
+
"typecheck": true
|
|
35
36
|
},
|
|
36
37
|
"engines": {
|
|
37
38
|
"node": "16 >=16.17 || 18 >=18.15.0 || >=20.6.1"
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/node": "^20.6.0",
|
|
50
51
|
"prettier": "^2.8.8",
|
|
51
|
-
"tap": "^18.0
|
|
52
|
+
"tap": "^18.5.0",
|
|
52
53
|
"typedoc": "^0.25.1"
|
|
53
54
|
},
|
|
54
55
|
"prettier": {
|