tshy 1.0.0-3 → 1.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.
Files changed (60) hide show
  1. package/README.md +45 -26
  2. package/dist/esm/add-dot.d.ts +3 -0
  3. package/dist/esm/add-dot.d.ts.map +1 -0
  4. package/dist/esm/add-dot.js +3 -0
  5. package/dist/esm/add-dot.js.map +1 -0
  6. package/dist/esm/build-commonjs.d.ts +3 -0
  7. package/dist/esm/build-commonjs.d.ts.map +1 -0
  8. package/dist/esm/build-commonjs.js +30 -0
  9. package/dist/esm/build-commonjs.js.map +1 -0
  10. package/dist/esm/build-esm.d.ts +3 -0
  11. package/dist/esm/build-esm.d.ts.map +1 -0
  12. package/dist/esm/build-esm.js +20 -0
  13. package/dist/esm/build-esm.js.map +1 -0
  14. package/dist/esm/build-fail.d.ts +6 -0
  15. package/dist/esm/build-fail.d.ts.map +1 -0
  16. package/dist/esm/build-fail.js +11 -0
  17. package/dist/esm/build-fail.js.map +1 -0
  18. package/dist/esm/build.d.ts +2 -0
  19. package/dist/esm/build.d.ts.map +1 -1
  20. package/dist/esm/build.js +16 -53
  21. package/dist/esm/build.js.map +1 -1
  22. package/dist/esm/config.d.ts.map +1 -1
  23. package/dist/esm/config.js +4 -61
  24. package/dist/esm/config.js.map +1 -1
  25. package/dist/esm/exports.d.ts +4 -1
  26. package/dist/esm/exports.d.ts.map +1 -1
  27. package/dist/esm/exports.js +14 -12
  28. package/dist/esm/exports.js.map +1 -1
  29. package/dist/esm/fail.d.ts +2 -1
  30. package/dist/esm/fail.d.ts.map +1 -1
  31. package/dist/esm/fail.js +1 -1
  32. package/dist/esm/fail.js.map +1 -1
  33. package/dist/esm/index.js +2 -2
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/package.d.ts +2 -2
  36. package/dist/esm/package.d.ts.map +1 -1
  37. package/dist/esm/package.js +3 -5
  38. package/dist/esm/package.js.map +1 -1
  39. package/dist/esm/resolve-export.d.ts +1 -1
  40. package/dist/esm/resolve-export.d.ts.map +1 -1
  41. package/dist/esm/resolve-export.js +10 -8
  42. package/dist/esm/resolve-export.js.map +1 -1
  43. package/dist/esm/set-folder-dialect.d.ts.map +1 -1
  44. package/dist/esm/set-folder-dialect.js.map +1 -1
  45. package/dist/esm/types.d.ts +1 -1
  46. package/dist/esm/types.d.ts.map +1 -1
  47. package/dist/esm/types.js.map +1 -1
  48. package/dist/esm/valid-dialects.d.ts +4 -0
  49. package/dist/esm/valid-dialects.d.ts.map +1 -0
  50. package/dist/esm/valid-dialects.js +14 -0
  51. package/dist/esm/valid-dialects.js.map +1 -0
  52. package/dist/esm/valid-exports.d.ts +3 -0
  53. package/dist/esm/valid-exports.d.ts.map +1 -0
  54. package/dist/esm/valid-exports.js +34 -0
  55. package/dist/esm/valid-exports.js.map +1 -0
  56. package/dist/esm/valid-external-export.d.ts +4 -0
  57. package/dist/esm/valid-external-export.d.ts.map +1 -0
  58. package/dist/esm/valid-external-export.js +12 -0
  59. package/dist/esm/valid-external-export.js.map +1 -0
  60. package/package.json +8 -2
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # tshy - TypeScript HYbridizer
2
2
 
3
- Hybrid (CommonJS/ESM) TypeScript node package builder.
3
+ Hybrid (CommonJS/ESM) TypeScript node package builder. Write
4
+ modules that Just Work in ESM and CommonJS, in easy mode.
4
5
 
5
6
  This tool manages the `exports` in your package.json file, and
6
- builds your TypeScript program using `tsc` 5.2 in both ESM and
7
- CJS modes.
7
+ builds your TypeScript program using `tsc` 5.2, emitting both ESM
8
+ and CommonJS variants, [providing the full strength of
9
+ TypeScript’s checking for both output
10
+ formats](https://twitter.com/atcb/status/1702069237710479608).
8
11
 
9
12
  ## USAGE
10
13
 
@@ -35,11 +38,11 @@ points.
35
38
 
36
39
  ## Configuration
37
40
 
38
- Mostly, this is opinionated convention, and so there is very
39
- little to configure.
41
+ Mostly, this just uses opinionated convention, and so there is
42
+ very little to configure.
40
43
 
41
- Source must be in `./src`. Builds are in `./dist/cjs` for
42
- CommonJS and `./dist/mjs` for ESM.
44
+ Source must be in `./src`. Builds are in `./dist/commonjs` for
45
+ CommonJS and `./dist/esm` for ESM.
43
46
 
44
47
  There is very little configuration for this. The only thing to
45
48
  decide is the exported paths. If you have a `./index.ts` file,
@@ -69,12 +72,12 @@ appropriate build target locations, like:
69
72
  "exports": {
70
73
  "./foo": {
71
74
  "import": {
72
- "types": "./dist/mjs/foo.d.ts",
73
- "default": "./dist/mjs/foo.js"
75
+ "types": "./dist/esm/foo.d.ts",
76
+ "default": "./dist/esm/foo.js"
74
77
  },
75
78
  "require": {
76
- "types": "./dist/cjs/foo.d.ts",
77
- "default": "./dist/cjs/foo.js"
79
+ "types": "./dist/commonjs/foo.d.ts",
80
+ "default": "./dist/commonjs/foo.js"
78
81
  }
79
82
  }
80
83
  }
@@ -82,16 +85,27 @@ appropriate build target locations, like:
82
85
  ```
83
86
 
84
87
  Any exports that are not within `./src` will not be built, and
85
- can be either a string, or a `{ import, require, types }` object:
88
+ can be anything supported by package.json `exports`, as they will
89
+ just be passed through as-is.
86
90
 
87
91
  ```json
88
92
  {
89
- "exports": {
90
- "./package.json": "./package.json"
91
- "./thing": {
92
- "import": "./lib/thing.mjs",
93
- "require": "./lib/thing.cjs",
94
- "types": "./lib/thing.d.ts"
93
+ "tshy": {
94
+ "exports": {
95
+ ".": "./src/my-built-module.ts",
96
+ "./package.json": "./package.json"
97
+ "./thing": {
98
+ "import": "./lib/thing.mjs",
99
+ "require": "./lib/thing.cjs",
100
+ "types": "./lib/thing.d.ts"
101
+ },
102
+ "./arraystyle": [
103
+ { "import": "./no-op.js" },
104
+ { "browser": "./browser-thing.js" },
105
+ { "require": [{ "types": "./using-require.d.ts" }, "./using-require.js"],
106
+ { "types": "./blah.d.ts" },
107
+ "./etc.js"
108
+ ]
95
109
  }
96
110
  }
97
111
  }
@@ -137,7 +151,7 @@ To do this, create a polyfill file with the CommonJS code in
137
151
  ```js
138
152
  // src/source-dir-cjs.cts
139
153
  // ^^^^^^^^^^--------- matching name
140
- // ^^^^----- "-cts" tag
154
+ // ^^^^----- "-cjs" tag
141
155
  // ^^^^- ".cts" filename suffix
142
156
  // this one has a -cjs.cts suffix, so it will override the
143
157
  // module at src/source-dir.ts in the CJS build,
@@ -149,23 +163,28 @@ export const sourceDir = pathToFileURL(__dirname)
149
163
 
150
164
  Then put the "real" ESM code in `<name>.ts` (not `.mts`!)
151
165
 
166
+ You will generally have to `//@ts-ignore` a bunch of stuff to get
167
+ the CommonJS build to ignore it, so it's best to keep the
168
+ polyfill surface as small as possible.
169
+
152
170
  ```js
153
171
  // src/source-dir.ts
154
172
  // This is the ESM version of the module
173
+ //@ts-ignore
155
174
  export const sourceDir = new URL('.', import.meta.url)
156
175
  ```
157
176
 
158
177
  Then in your code, you can just `import { sourceDir } from
159
- './source-dir.js'` and it'll work in both dialects.
178
+ './source-dir.js'` and it'll work in both builds.
160
179
 
161
- ## `.cts` and `.mts` files
180
+ ## Excluding from a build using `.cts` and `.mts` files
162
181
 
163
182
  Files named `*.mts` will be excluded from the CommonJS build.
164
183
 
165
184
  Files named `*.cts` will be excluded from the ESM build.
166
185
 
167
- If you need to do something one way for CJS and another way for
168
- ESM, use the "Dialect Switching" trick, with the ESM code living
186
+ If you need to do something one way for CommonJS and another way for
187
+ esm, use the "Dialect Switching" trick, with the ESM code living
169
188
  in `src/<whatever>.ts` and the CommonJS polyfill living in
170
189
  `src/<whatever>-cjs.cts`.
171
190
 
@@ -200,7 +219,7 @@ If you don't provide that config, then the default is:
200
219
  Using the `imports` field in `package.json` is not currently
201
220
  supported, because this looks at the nearest `package.json` to
202
221
  get local imports, and the package.json files placed in
203
- `dist/{cjs,mjs}` can't have local imports outside of their
222
+ `dist/{commonjs,esm}` can't have local imports outside of their
204
223
  folders.
205
224
 
206
225
  There's a way it could theoretically be done, but it's a bit
@@ -225,12 +244,12 @@ If you don't have a `tsconfig.json` file, then one will be
225
244
  provided for you.
226
245
 
227
246
  Then the `tsconfig.json` file will be used as the default project
228
- for code hints in VSCode/nvim, your tests, etc.
247
+ for code hints in VSCode, neovim, tests, etc.
229
248
 
230
249
  ## `src/package.json`
231
250
 
232
251
  As of TypeScript 5.2, the only way to emit JavaScript to ESM or
233
- CJS, and also import packages using node-style `"exports"`-aware
252
+ cjs, and also import packages using node-style `"exports"`-aware
234
253
  module resolution, is to set the `type` field in the
235
254
  `package.json` file closest to the TypeScript source code.
236
255
 
@@ -0,0 +1,3 @@
1
+ declare const _default: (s: string) => string;
2
+ export default _default;
3
+ //# sourceMappingURL=add-dot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-dot.d.ts","sourceRoot":"","sources":["../../src/add-dot.ts"],"names":[],"mappings":"4BACmB,MAAM;AAAzB,wBAA4C"}
@@ -0,0 +1,3 @@
1
+ import { join } from 'node:path/posix';
2
+ export default (s) => `./${join(s)}`;
3
+ //# sourceMappingURL=add-dot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-dot.js","sourceRoot":"","sources":["../../src/add-dot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,eAAe,CAAC,CAAS,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA","sourcesContent":["import { join } from 'node:path/posix'\nexport default (s: string) => `./${join(s)}`\n"]}
@@ -0,0 +1,3 @@
1
+ import './tsconfig.js';
2
+ export declare const buildCommonJS: () => undefined;
3
+ //# sourceMappingURL=build-commonjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-commonjs.d.ts","sourceRoot":"","sources":["../../src/build-commonjs.ts"],"names":[],"mappings":"AAQA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,aAAa,iBAwBzB,CAAA"}
@@ -0,0 +1,30 @@
1
+ import chalk from 'chalk';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { renameSync } from 'node:fs';
4
+ import { relative, resolve } from 'node:path/posix';
5
+ import buildFail from './build-fail.js';
6
+ import * as console from './console.js';
7
+ import polyfills from './polyfills.js';
8
+ import setFolderDialect from './set-folder-dialect.js';
9
+ import './tsconfig.js';
10
+ export const buildCommonJS = () => {
11
+ console.debug(chalk.cyan.dim('building commonjs'));
12
+ setFolderDialect('src', 'commonjs');
13
+ const res = spawnSync('tsc -p .tshy/commonjs.json', {
14
+ shell: true,
15
+ stdio: 'inherit',
16
+ });
17
+ setFolderDialect('src');
18
+ if (res.status || res.signal)
19
+ return buildFail(res);
20
+ setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs');
21
+ console.error(chalk.cyan.bold('built commonjs'));
22
+ // apply polyfills
23
+ for (const [f, t] of polyfills.entries()) {
24
+ const stemFrom = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(f))).replace(/\.cts$/, '');
25
+ const stemTo = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(t))).replace(/\.tsx?$/, '');
26
+ renameSync(`${stemFrom}.cjs`, `${stemTo}.js`);
27
+ renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`);
28
+ }
29
+ };
30
+ //# sourceMappingURL=build-commonjs.js.map
@@ -0,0 +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;AACpC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;AAEtB,MAA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nimport { spawnSync } from 'node:child_process'\nimport { renameSync } from 'node:fs'\nimport { relative, resolve } from 'node:path/posix'\nimport buildFail from './build-fail.js'\nimport * as console from './console.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\n\nexport const buildCommonJS = () => {\n console.debug(chalk.cyan.dim('building commonjs'))\n setFolderDialect('src', 'commonjs')\n const res = spawnSync('tsc -p .tshy/commonjs.json', {\n shell: true,\n stdio: 'inherit',\n })\n setFolderDialect('src')\n if (res.status || res.signal) return buildFail(res)\n setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs')\n console.error(chalk.cyan.bold('built commonjs'))\n // apply polyfills\n for (const [f, t] of polyfills.entries()) {\n const stemFrom = resolve(\n '.tshy-build-tmp/commonjs',\n relative(resolve('src'), resolve(f))\n ).replace(/\\.cts$/, '')\n const stemTo = resolve(\n '.tshy-build-tmp/commonjs',\n relative(resolve('src'), resolve(t))\n ).replace(/\\.tsx?$/, '')\n renameSync(`${stemFrom}.cjs`, `${stemTo}.js`)\n renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`)\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import './tsconfig.js';
2
+ export declare const buildESM: () => undefined;
3
+ //# sourceMappingURL=build-esm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-esm.d.ts","sourceRoot":"","sources":["../../src/build-esm.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,QAAQ,iBAWpB,CAAA"}
@@ -0,0 +1,20 @@
1
+ import chalk from 'chalk';
2
+ import { spawnSync } from 'node:child_process';
3
+ import buildFail from './build-fail.js';
4
+ import * as console from './console.js';
5
+ import setFolderDialect from './set-folder-dialect.js';
6
+ import './tsconfig.js';
7
+ export const buildESM = () => {
8
+ console.debug(chalk.cyan.dim('building esm'));
9
+ setFolderDialect('src', 'esm');
10
+ const res = spawnSync('tsc -p .tshy/esm.json', {
11
+ shell: true,
12
+ stdio: 'inherit',
13
+ });
14
+ 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
+ };
20
+ //# sourceMappingURL=build-esm.js.map
@@ -0,0 +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;AAEtB,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAA;IAC7C,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC9B,MAAM,GAAG,GAAG,SAAS,CAAC,uBAAuB,EAAE;QAC7C,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;IACF,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAA;IACnD,gBAAgB,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;AAC7C,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync } from 'node:child_process'\nimport buildFail from './build-fail.js'\nimport * as console from './console.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\n\nexport const buildESM = () => {\n console.debug(chalk.cyan.dim('building esm'))\n setFolderDialect('src', 'esm')\n const res = spawnSync('tsc -p .tshy/esm.json', {\n shell: true,\n stdio: 'inherit',\n })\n setFolderDialect('src')\n if (res.status || res.signal) return buildFail(res)\n setFolderDialect('.tshy-build-tmp/esm', 'esm')\n console.error(chalk.cyan.bold('built esm'))\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { SpawnSyncReturns } from 'node:child_process';
3
+ import './tsconfig.js';
4
+ declare const _default: (res: SpawnSyncReturns<Buffer>) => never;
5
+ export default _default;
6
+ //# sourceMappingURL=build-fail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-fail.d.ts","sourceRoot":"","sources":["../../src/build-fail.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAIrD,OAAO,eAAe,CAAA;8BAED,iBAAiB,MAAM,CAAC;AAA7C,wBAKC"}
@@ -0,0 +1,11 @@
1
+ import * as console from './console.js';
2
+ import fail from './fail.js';
3
+ import setFolderDialect from './set-folder-dialect.js';
4
+ import './tsconfig.js';
5
+ export default (res) => {
6
+ setFolderDialect('src');
7
+ fail('build failed');
8
+ console.error(res);
9
+ process.exit(1);
10
+ };
11
+ //# sourceMappingURL=build-fail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-fail.js","sourceRoot":"","sources":["../../src/build-fail.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;AAEtB,eAAe,CAAC,GAA6B,EAAE,EAAE;IAC/C,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,CAAC,cAAc,CAAC,CAAA;IACpB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import { SpawnSyncReturns } from 'node:child_process'\nimport * as console from './console.js'\nimport fail from './fail.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\n\nexport default (res: SpawnSyncReturns<Buffer>) => {\n setFolderDialect('src')\n fail('build failed')\n console.error(res)\n process.exit(1)\n}\n"]}
@@ -1,2 +1,4 @@
1
1
  import './tsconfig.js';
2
+ declare const _default: () => void;
3
+ export default _default;
2
4
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAYA,OAAO,eAAe,CAAA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAQA,OAAO,eAAe,CAAA;;AAGtB,wBAcC"}
package/dist/esm/build.js CHANGED
@@ -1,63 +1,26 @@
1
1
  import chalk from 'chalk';
2
- import { spawnSync } from 'node:child_process';
3
- import { renameSync } from 'node:fs';
4
- import { relative, resolve } from 'node:path/posix';
5
2
  import { rimrafSync } from 'rimraf';
6
3
  import { syncContentSync } from 'sync-content';
7
4
  import bins from './bins.js';
5
+ import { buildCommonJS } from './build-commonjs.js';
6
+ import { buildESM } from './build-esm.js';
8
7
  import * as console from './console.js';
9
8
  import dialects from './dialects.js';
10
- import { fail } from './fail.js';
11
- import polyfills from './polyfills.js';
12
- import setFolderDialect from './set-folder-dialect.js';
13
9
  import './tsconfig.js';
14
10
  import writePackage from './write-package.js';
15
- const buildFail = (res) => {
16
- setFolderDialect('src');
17
- fail('build failed');
18
- console.error(res);
19
- process.exit(1);
11
+ export default () => {
12
+ rimrafSync('.tshy-build-tmp');
13
+ if (dialects.includes('esm'))
14
+ buildESM();
15
+ if (dialects.includes('commonjs'))
16
+ buildCommonJS();
17
+ console.debug(chalk.cyan.dim('moving to ./dist'));
18
+ syncContentSync('.tshy-build-tmp', 'dist');
19
+ console.debug(chalk.cyan.dim('removing build temp dir'));
20
+ rimrafSync('.tshy-build-tmp');
21
+ console.debug(chalk.cyan.dim('chmod bins'));
22
+ bins();
23
+ console.debug(chalk.cyan.dim('write package.json'));
24
+ writePackage();
20
25
  };
21
- rimrafSync('.tshy-build-tmp');
22
- if (dialects.includes('esm')) {
23
- setFolderDialect('src', 'esm');
24
- console.debug(chalk.cyan.dim('building esm'));
25
- const res = spawnSync('tsc -p .tshy/esm.json', {
26
- shell: true,
27
- stdio: 'inherit',
28
- });
29
- setFolderDialect('src');
30
- if (res.status || res.signal)
31
- buildFail(res);
32
- setFolderDialect('.tshy-build-tmp/esm', 'esm');
33
- console.error(chalk.cyan.bold('built esm'));
34
- }
35
- if (dialects.includes('commonjs')) {
36
- setFolderDialect('src', 'commonjs');
37
- console.debug(chalk.cyan.dim('building commonjs'));
38
- const res = spawnSync('tsc -p .tshy/commonjs.json', {
39
- shell: true,
40
- stdio: 'inherit',
41
- });
42
- setFolderDialect('src');
43
- if (res.status || res.signal)
44
- buildFail(res);
45
- setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs');
46
- console.error(chalk.cyan.bold('built commonjs'));
47
- // apply polyfills
48
- for (const [f, t] of polyfills.entries()) {
49
- const stemFrom = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(f))).replace(/\.cts$/, '');
50
- const stemTo = resolve('.tshy-build-tmp/commonjs', relative(resolve('src'), resolve(t))).replace(/\.tsx?$/, '');
51
- renameSync(`${stemFrom}.cjs`, `${stemTo}.js`);
52
- renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`);
53
- }
54
- }
55
- console.debug(chalk.cyan.dim('moving to ./dist'));
56
- syncContentSync('.tshy-build-tmp', 'dist');
57
- console.debug(chalk.cyan.dim('removing build temp dir'));
58
- rimrafSync('.tshy-build-tmp');
59
- console.debug(chalk.cyan.dim('chmod bins'));
60
- bins();
61
- console.debug(chalk.cyan.dim('write package.json'));
62
- writePackage();
63
26
  //# sourceMappingURL=build.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAoB,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,gBAAgB,MAAM,yBAAyB,CAAA;AACtD,OAAO,eAAe,CAAA;AACtB,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAE7C,MAAM,SAAS,GAAG,CAAC,GAA6B,EAAE,EAAE;IAClD,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,CAAC,cAAc,CAAC,CAAA;IACpB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAA;AAED,UAAU,CAAC,iBAAiB,CAAC,CAAA;AAE7B,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;IAC5B,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAA;I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C,QAAQ,EAAE,EAAE,CAAC,CAAA;QACvB,MAAM,MAAM,GAAG,OAAO,CACpB,0BAA0B,EAC1B,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CACrC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QACxB,UAAU,CAAC,GAAG,QAAQ,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,CAAA;QAC7C,UAAU,CAAC,GAAG,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,CAAC,CAAA;KAClD;CACF;AAED,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAA;AACjD,eAAe,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;AAC1C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,CAAA;AACxD,UAAU,CAAC,iBAAiB,CAAC,CAAA;AAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAA;AAC3C,IAAI,EAAE,CAAA;AACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAA;AACnD,YAAY,EAAE,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { spawnSync, SpawnSyncReturns } from 'node:child_process'\nimport { renameSync } from 'node:fs'\nimport { relative, resolve } from 'node:path/posix'\nimport { rimrafSync } from 'rimraf'\nimport { syncContentSync } from 'sync-content'\nimport bins from './bins.js'\nimport * as console from './console.js'\nimport dialects from './dialects.js'\nimport { fail } from './fail.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport './tsconfig.js'\nimport writePackage from './write-package.js'\n\nconst buildFail = (res: SpawnSyncReturns<Buffer>) => {\n setFolderDialect('src')\n fail('build failed')\n console.error(res)\n process.exit(1)\n}\n\nrimrafSync('.tshy-build-tmp')\n\nif (dialects.includes('esm')) {\n setFolderDialect('src', 'esm')\n console.debug(chalk.cyan.dim('building esm'))\n const res = spawnSync('tsc -p .tshy/esm.json', {\n shell: true,\n stdio: 'inherit',\n })\n setFolderDialect('src')\n if (res.status || res.signal) buildFail(res)\n setFolderDialect('.tshy-build-tmp/esm', 'esm')\n console.error(chalk.cyan.bold('built esm'))\n}\n\nif (dialects.includes('commonjs')) {\n setFolderDialect('src', 'commonjs')\n console.debug(chalk.cyan.dim('building commonjs'))\n const res = spawnSync('tsc -p .tshy/commonjs.json', {\n shell: true,\n stdio: 'inherit',\n })\n setFolderDialect('src')\n if (res.status || res.signal) buildFail(res)\n setFolderDialect('.tshy-build-tmp/commonjs', 'commonjs')\n console.error(chalk.cyan.bold('built commonjs'))\n // apply polyfills\n for (const [f, t] of polyfills.entries()) {\n const stemFrom = resolve(\n '.tshy-build-tmp/commonjs',\n relative(resolve('src'), resolve(f))\n ).replace(/\\.cts$/, '')\n const stemTo = resolve(\n '.tshy-build-tmp/commonjs',\n relative(resolve('src'), resolve(t))\n ).replace(/\\.tsx?$/, '')\n renameSync(`${stemFrom}.cjs`, `${stemTo}.js`)\n renameSync(`${stemFrom}.d.cts`, `${stemTo}.d.ts`)\n }\n}\n\nconsole.debug(chalk.cyan.dim('moving to ./dist'))\nsyncContentSync('.tshy-build-tmp', 'dist')\nconsole.debug(chalk.cyan.dim('removing build temp dir'))\nrimrafSync('.tshy-build-tmp')\nconsole.debug(chalk.cyan.dim('chmod bins'))\nbins()\nconsole.debug(chalk.cyan.dim('write package.json'))\nwritePackage()\n"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,eAAe,CAAA;AACtB,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAE7C,eAAe,GAAG,EAAE;IAClB,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7B,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,QAAQ,EAAE,CAAA;IACxC,IAAI,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,aAAa,EAAE,CAAA;IAElD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAA;IACjD,eAAe,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;IAC1C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,CAAA;IACxD,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAA;IAC3C,IAAI,EAAE,CAAA;IACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACnD,YAAY,EAAE,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { rimrafSync } from 'rimraf'\nimport { syncContentSync } from 'sync-content'\nimport bins from './bins.js'\nimport { buildCommonJS } from './build-commonjs.js'\nimport { buildESM } from './build-esm.js'\nimport * as console from './console.js'\nimport dialects from './dialects.js'\nimport './tsconfig.js'\nimport writePackage from './write-package.js'\n\nexport default () => {\n rimrafSync('.tshy-build-tmp')\n\n if (dialects.includes('esm')) buildESM()\n if (dialects.includes('commonjs')) buildCommonJS()\n\n console.debug(chalk.cyan.dim('moving to ./dist'))\n syncContentSync('.tshy-build-tmp', 'dist')\n console.debug(chalk.cyan.dim('removing build temp dir'))\n rimrafSync('.tshy-build-tmp')\n console.debug(chalk.cyan.dim('chmod bins'))\n bins()\n console.debug(chalk.cyan.dim('write package.json'))\n writePackage()\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAA4B,UAAU,EAAE,MAAM,YAAY,CAAA;AA4GjE,QAAA,MAAM,MAAM,EAAE,UAAoC,CAAA;AAClD,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;AA8BhD,QAAA,MAAM,MAAM,EAAE,UAAoC,CAAA;AAClD,eAAe,MAAM,CAAA"}
@@ -1,65 +1,12 @@
1
1
  // get the config and package and stuff
2
- import { fail } from './fail.js';
2
+ import pkg from './package.js';
3
+ import sources from './sources.js';
4
+ import validDialects from './valid-dialects.js';
5
+ import validExports from './valid-exports.js';
3
6
  const validConfig = (e) => !!e &&
4
7
  typeof e === 'object' &&
5
8
  (e.exports === undefined || validExports(e['exports'])) &&
6
9
  (e.dialects === undefined || validDialects(e['dialects']));
7
- const isDialect = (d) => d === 'commonjs' || d === 'esm';
8
- const validDialects = (d) => !!d && Array.isArray(d) && !d.some(d => !isDialect(d));
9
- const validExternalExport = (exp) => {
10
- const i = resolveExport(exp, 'import');
11
- const r = resolveExport(exp, 'require');
12
- if (!i && !r)
13
- return false;
14
- if (i && join(i).startsWith('src/'))
15
- return false;
16
- if (r && join(r).startsWith('src/'))
17
- return false;
18
- return true;
19
- };
20
- const validExports = (e) => {
21
- if (!e)
22
- return false;
23
- if (typeof e !== 'object')
24
- return false;
25
- for (const [sub, exp] of Object.entries(e)) {
26
- if (sub !== '.' && !sub.startsWith('./')) {
27
- fail(`tshy.exports key must be "." or start with "./", got: ${sub}`);
28
- process.exit(1);
29
- }
30
- // just a module. either a built export, or a simple unbuilt export
31
- if (typeof exp === 'string') {
32
- e[sub] = addDot(exp);
33
- continue;
34
- }
35
- if (typeof exp !== 'object' || !exp || Array.isArray(exp)) {
36
- fail(`tshy.exports ${sub} value must be string or import/require object, ` +
37
- `got: ${JSON.stringify(exp)}`);
38
- process.exit(1);
39
- }
40
- // can be:
41
- // "./sub": "./unbuilt.js"
42
- // "./sub": { require: "./unbuilt.js", types: "./unbuilt.d.ts" }
43
- // "./sub": {require:"./u.cjs",import:"./u.cjs",types:"./u.dts"}
44
- // "./sub": {import:{types:"u.d.ts",default:"u.js"},require:{types:"u.d.cts", default:"u.cjs"}}
45
- // Just verify that import and require resolutions are not in src
46
- if (!validExternalExport(exp)) {
47
- fail(`tshy.exports ${sub} unbuilt exports must not be in ./src, ` +
48
- `and exports in src must be string values. ` +
49
- `got: ${JSON.stringify(exp)}`);
50
- process.exit(1);
51
- }
52
- e[sub] = exp;
53
- }
54
- if (e.dialects) {
55
- if (!validDialects(e.dialects)) {
56
- fail(`tshy.dialects must be array containing 'esm' and/or 'commonjs', ` +
57
- `got: ${JSON.stringify(e.dialects)}`);
58
- }
59
- }
60
- return true;
61
- };
62
- const addDot = (s) => `./${join(s)}`;
63
10
  const getConfig = (pkg, sources) => {
64
11
  const tshy = validConfig(pkg.tshy) ? pkg.tshy : {};
65
12
  if (tshy.exports)
@@ -77,10 +24,6 @@ const getConfig = (pkg, sources) => {
77
24
  tshy.exports = e;
78
25
  return tshy;
79
26
  };
80
- import { join } from 'path/posix';
81
- import pkg from './package.js';
82
- import sources from './sources.js';
83
- import { resolveExport } from './resolve-export.js';
84
27
  const config = getConfig(pkg, sources);
85
28
  export default config;
86
29
  //# s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e,MAAM,CAAA","sourcesContent":["// get the config and package and stuff\n\nimport { fail } from './fail.js'\nimport { Dialect, Export, Package, TshyConfig } from './types.js'\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\nconst isDialect = (d: any): d is Dialect =>\n d === 'commonjs' || d === 'esm'\n\nconst validDialects = (\n d: any\n): d is Exclude<TshyConfig['dialects'], undefined> =>\n !!d && Array.isArray(d) && !d.some(d => !isDialect(d))\n\nconst validExternalExport = (exp: any): exp is Export => {\n const i = resolveExport(exp, 'import')\n const r = resolveExport(exp, 'require')\n if (!i && !r) return false\n if (i && join(i).startsWith('src/')) return false\n if (r && join(r).startsWith('src/')) return false\n return true\n}\n\nconst validExports = (\n e: any\n): e is Exclude<TshyConfig['exports'], undefined> => {\n if (!e) return false\n if (typeof e !== 'object') 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 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' || !exp || Array.isArray(exp)) {\n fail(\n `tshy.exports ${sub} value must be string or import/require object, ` +\n `got: ${JSON.stringify(exp)}`\n )\n process.exit(1)\n }\n\n // can be:\n // \"./sub\": \"./unbuilt.js\"\n // \"./sub\": { require: \"./unbuilt.js\", types: \"./unbuilt.d.ts\" }\n // \"./sub\": {require:\"./u.cjs\",import:\"./u.cjs\",types:\"./u.dts\"}\n // \"./sub\": {import:{types:\"u.d.ts\",default:\"u.js\"},require:{types:\"u.d.cts\", default:\"u.cjs\"}}\n // Just verify that import and require resolutions are not in src\n\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 process.exit(1)\n }\n\n e[sub] = exp\n }\n if (e.dialects) {\n if (!validDialects(e.dialects)) {\n fail(\n `tshy.dialects must be array containing 'esm' and/or 'commonjs', ` +\n `got: ${JSON.stringify(e.dialects)}`\n )\n }\n }\n return true\n}\n\nconst addDot = (s: string) => `./${join(s)}`\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\nimport { join } from 'path/posix'\nimport pkg from './package.js'\nimport sources from './sources.js'\nimport { resolveExport } from './resolve-export.js'\n\nconst config: TshyConfig = getConfig(pkg, sources)\nexport default config\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC/C,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAE7C,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,SAAS,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;AAE5D,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 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'\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\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"]}
@@ -1,4 +1,7 @@
1
- import { Export } from './types.js';
1
+ import { Export, TshyConfig, TshyExport } from './types.js';
2
+ export declare const getImpTarget: (s: string | TshyExport | undefined | null) => string | undefined | null;
3
+ export declare const getReqTarget: (s: string | TshyExport | undefined | null, polyfills: Map<string, string>) => string | null | undefined;
4
+ export declare const getExports: (c: TshyConfig, polyfills: Map<string, string>) => Record<string, Export>;
2
5
  declare const _default: Record<string, Export>;
3
6
  export default _default;
4
7
  //# sourceMappingURL=exports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAA0B,MAAM,YAAY,CAAA;;AAsF3D,wBAA0D"}
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE3D,eAAO,MAAM,YAAY,MACpB,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,KACxC,MAAM,GAAG,SAAS,GAAG,IAcvB,CAAA;AAED,eAAO,MAAM,YAAY,MACpB,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,aAC9B,IAAI,MAAM,EAAE,MAAM,CAAC,KAC7B,MAAM,GAAG,IAAI,GAAG,SAclB,CAAA;AAED,eAAO,MAAM,UAAU,MAClB,UAAU,aACF,IAAI,MAAM,EAAE,MAAM,CAAC,KAC7B,OAAO,MAAM,EAAE,MAAM,CAwCvB,CAAA;;AAMD,wBAA0D"}
@@ -1,11 +1,11 @@
1
1
  import { relative, resolve } from 'node:path/posix';
2
2
  import config from './config.js';
3
3
  import dialects from './dialects.js';
4
- import { fail } from './fail.js';
4
+ 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
- const getImpTarget = (s) => {
8
+ export const getImpTarget = (s) => {
9
9
  if (s === undefined)
10
10
  return undefined;
11
11
  if (typeof s === 'string') {
@@ -16,11 +16,9 @@ const getImpTarget = (s) => {
16
16
  ? `./dist/esm/${relative(resolve('./src'), resolve(imp)).replace(/\.(m?)tsx?$/, '.$1js')}`
17
17
  : undefined;
18
18
  }
19
- if (s && typeof s === 'object') {
20
- return resolveExport(s, 'import');
21
- }
19
+ return resolveExport(s, 'import');
22
20
  };
23
- const getReqTarget = (s, polyfills) => {
21
+ export const getReqTarget = (s, polyfills) => {
24
22
  if (s === undefined)
25
23
  return undefined;
26
24
  if (typeof s === 'string') {
@@ -31,27 +29,31 @@ const getReqTarget = (s, polyfills) => {
31
29
  ? `./dist/commonjs/${relative(resolve('./src'), resolve(polyfills.get(req) || req)).replace(/\.(c?)tsx?$/, '.$1js')}`
32
30
  : undefined;
33
31
  }
34
- if (s && typeof s === 'object') {
35
- return getReqTarget(resolveExport(s, 'require'), polyfills);
36
- }
32
+ return getReqTarget(resolveExport(s, 'require'), polyfills);
37
33
  };
38
- const getExports = (c, polyfills) => {
34
+ export const getExports = (c, polyfills) => {
35
+ // by this time it always exports, will get the default if missing
36
+ /* c8 ignore start */
39
37
  if (!c.exports) {
40
38
  fail('no exports on tshy config (is there code in ./src?)');
41
39
  process.exit(1);
42
40
  }
41
+ /* c8 ignore stop */
43
42
  const e = {};
44
43
  for (const [sub, s] of Object.entries(c.exports)) {
45
- const impTarget = getImpTarget(s);
46
- const reqTarget = getReqTarget(s, polyfills);
47
44
  // external export, not built by us
48
45
  if (typeof s !== 'string' || !s.startsWith('./src/')) {
49
46
  // already been validated, just accept as-is
50
47
  e[sub] = s;
51
48
  continue;
52
49
  }
50
+ const impTarget = getImpTarget(s);
51
+ const reqTarget = getReqTarget(s, polyfills);
52
+ // should be impossible
53
+ /* c8 ignore start */
53
54
  if (!impTarget && !reqTarget)
54
55
  continue;
56
+ /* c8 ignore stop */
55
57
  const exp = (e[sub] = {});
56
58
  if (impTarget) {
57
59
  exp.import = {
@@ -1 +1 @@
1
- {"version":3,"file":"exports.js","sourceRoot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;YACpD,4CAA4C;YAC5C,CAAC,CAAC,GAAG,CAAC,GAAG,CAAW,CAAA;YACpB,SAAQ;SACT;QAED,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS;YAAE,SAAQ;QAEtC,MAAM,GAAG,GAAW,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAA;QACjC,IAAI,SAAS,EAAE;YACb,GAAG,CAAC,MAAM,GAAG;gBACX,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC;gBAChD,OAAO,EAAE,SAAS;aACnB,CAAA;SACF;QACD,IAAI,SAAS,EAAE;YACb,GAAG,CAAC,OAAO,GAAG;gBACZ,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC;gBAChD,OAAO,EAAE,SAAS;aACnB,CAAA;SACF;KACF;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,qEAAqE;AACrE,OAAO,GAAG,CAAC,MAAM,CAAA;AACjB,OAAO,GAAG,CAAC,IAAI,CAAA;AACf,OAAO,GAAG,CAAC,KAAK,CAAA;AAChB,eAAe,GAAG,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA","sourcesContent":["import { relative, resolve } from 'node:path/posix'\nimport config from './config.js'\nimport dialects from './dialects.js'\nimport { fail } from './fail.js'\nimport pkg from './package.js'\nimport polyfills from './polyfills.js'\nimport { resolveExport } from './resolve-export.js'\nimport { Export, TshyConfig, TshyExport } from './types.js'\n\nconst getImpTarget = (\n s: string | TshyExport | undefined\n): string | undefined => {\n if (s === undefined) return undefined\n if (typeof s === 'string') {\n const imp = s.endsWith('.cts') ? undefined : s\n return !imp || !imp.startsWith('./src/')\n ? imp\n : dialects.includes('esm')\n ? `./dist/esm/${relative(\n resolve('./src'),\n resolve(imp)\n ).replace(/\\.(m?)tsx?$/, '.$1js')}`\n : undefined\n }\n if (s && typeof s === 'object') {\n return resolveExport(s, 'import')\n }\n}\n\nconst getReqTarget = (\n s: string | TshyExport | undefined,\n polyfills: Map<string, string>\n): string | undefined => {\n if (s === undefined) return undefined\n if (typeof s === 'string') {\n const req = s.endsWith('.mts') ? undefined : s\n return !req || !req.startsWith('./src/')\n ? req\n : dialects.includes('commonjs')\n ? `./dist/commonjs/${relative(\n resolve('./src'),\n resolve(polyfills.get(req) || req)\n ).replace(/\\.(c?)tsx?$/, '.$1js')}`\n : undefined\n }\n if (s && typeof s === 'object') {\n return getReqTarget(resolveExport(s, 'require'), polyfills)\n }\n}\n\nconst getExports = (\n c: TshyConfig,\n polyfills: Map<string, string>\n): Record<string, Export> => {\n if (!c.exports) {\n fail('no exports on tshy config (is there code in ./src?)')\n process.exit(1)\n }\n const e: Record<string, Export> = {}\n for (const [sub, s] of Object.entries(c.exports)) {\n const impTarget = getImpTarget(s)\n const reqTarget = getReqTarget(s, polyfills)\n\n // external export, not built by us\n if (typeof s !== 'string' || !s.startsWith('./src/')) {\n // already been validated, just accept as-is\n e[sub] = s as Export\n continue\n }\n\n if (!impTarget && !reqTarget) continue\n\n const exp: Export = (e[sub] = {})\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\n// These are all defined by exports, so it's just confusing otherwise\ndelete pkg.module\ndelete pkg.main\ndelete pkg.types\nexport default pkg.exports = getExports(config, polyfills)\n"]}
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,G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SAAS,EAAE;YACb,GAAG,CAAC,MAAM,GAAG;gBACX,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC;gBAChD,OAAO,EAAE,SAAS;aACnB,CAAA;SACF;QACD,IAAI,SAAS,EAAE;YACb,GAAG,CAAC,OAAO,GAAG;gBACZ,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC;gBAChD,OAAO,EAAE,SAAS;aACnB,CAAA;SACF;KACF;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,qEAAqE;AACrE,OAAO,GAAG,CAAC,MAAM,CAAA;AACjB,OAAO,GAAG,CAAC,IAAI,CAAA;AACf,OAAO,GAAG,CAAC,KAAK,CAAA;AAChB,eAAe,GAAG,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA","sourcesContent":["import { relative, resolve } from 'node:path/posix'\nimport config from './config.js'\nimport dialects from './dialects.js'\nimport fail from './fail.js'\nimport pkg from './package.js'\nimport polyfills from './polyfills.js'\nimport { resolveExport } from './resolve-export.js'\nimport { Export, TshyConfig, TshyExport } from './types.js'\n\nexport const getImpTarget = (\n s: string | TshyExport | undefined | null\n): string | undefined | null => {\n if (s === undefined) return undefined\n if (typeof s === 'string') {\n const imp = s.endsWith('.cts') ? undefined : s\n return !imp || !imp.startsWith('./src/')\n ? imp\n : dialects.includes('esm')\n ? `./dist/esm/${relative(\n resolve('./src'),\n resolve(imp)\n ).replace(/\\.(m?)tsx?$/, '.$1js')}`\n : undefined\n }\n return resolveExport(s, 'import')\n}\n\nexport const getReqTarget = (\n s: string | TshyExport | undefined | null,\n polyfills: Map<string, string>\n): string | null | undefined => {\n if (s === undefined) return undefined\n if (typeof s === 'string') {\n const req = s.endsWith('.mts') ? undefined : s\n return !req || !req.startsWith('./src/')\n ? req\n : dialects.includes('commonjs')\n ? `./dist/commonjs/${relative(\n resolve('./src'),\n resolve(polyfills.get(req) || req)\n ).replace(/\\.(c?)tsx?$/, '.$1js')}`\n : undefined\n }\n return getReqTarget(resolveExport(s, 'require'), polyfills)\n}\n\nexport const getExports = (\n c: TshyConfig,\n polyfills: Map<string, string>\n): Record<string, Export> => {\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 process.exit(1)\n }\n /* c8 ignore stop */\n const e: Record<string, Export> = {}\n for (const [sub, s] of Object.entries(c.exports)) {\n // external export, not built by us\n if (typeof s !== 'string' || !s.startsWith('./src/')) {\n // already been validated, just accept as-is\n e[sub] = s as Export\n continue\n }\n\n const impTarget = getImpTarget(s)\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: Export = (e[sub] = {})\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\n// These are all defined by exports, so it's just confusing otherwise\ndelete pkg.module\ndelete pkg.main\ndelete pkg.types\nexport default pkg.exports = getExports(config, polyfills)\n"]}
@@ -1,2 +1,3 @@
1
- export declare const fail: (message: string, er?: Error) => void;
1
+ declare const _default: (message: string, er?: Error) => void;
2
+ export default _default;
2
3
  //# sourceMappingURL=fail.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fail.d.ts","sourceRoot":"","sources":["../../src/fail.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,YAAa,MAAM,OAAO,KAAK,SAI/C,CAAA"}
1
+ {"version":3,"file":"fail.d.ts","sourceRoot":"","sources":["../../src/fail.ts"],"names":[],"mappings":"kCAEyB,MAAM,OAAO,KAAK;AAA3C,wBAIC"}
package/dist/esm/fail.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import * as console from './console.js';
3
- export const fail = (message, er) => {
3
+ export default (message, er) => {
4
4
  console.error(chalk.red.bold(message));
5
5
  if (er)
6
6
  console.error(er.message);
@@ -1 +1 @@
1
- {"version":3,"file":"fail.js","sourceRoot":"","sources":["../../src/fail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,EAAU,EAAE,EAAE;IAClD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IACtC,IAAI,EAAE;QAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;IACjC,OAAO,CAAC,KAAK,EAAE,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport * as console from './console.js'\nexport const fail = (message: string, er?: Error) => {\n console.error(chalk.red.bold(message))\n if (er) console.error(er.message)\n console.print()\n}\n"]}
1
+ {"version":3,"file":"fail.js","sourceRoot":"","sources":["../../src/fail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,eAAe,CAAC,OAAe,EAAE,EAAU,EAAE,EAAE;IAC7C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IACtC,IAAI,EAAE;QAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;IACjC,OAAO,CAAC,KAAK,EAAE,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport * as console from './console.js'\nexport default (message: string, er?: Error) => {\n console.error(chalk.red.bold(message))\n if (er) console.error(er.message)\n console.print()\n}\n"]}
package/dist/esm/index.js CHANGED
@@ -3,11 +3,11 @@ import chalk from 'chalk';
3
3
  import * as console from './console.js';
4
4
  import './exports.js';
5
5
  import pkg from './package.js';
6
+ import build from './build.js';
6
7
  const { exports: exp, tshy } = pkg;
7
8
  console.debug(chalk.yellow.bold('building'), process.cwd());
8
9
  console.debug(chalk.cyan.dim('tshy config'), tshy);
9
10
  console.debug(chalk.cyan.dim('exports'), exp);
10
- // have our config, time to build
11
- await import('./build.js');
11
+ build();
12
12
  console.log(chalk.bold.green('success!'));
13
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,cAAc,CAAA;AACrB,OAAO,GAAG,MAAM,cAAc,CAAA;AAE9B,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;AAElC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;AAC3D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC,CAAA;AAClD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAA;AAE7C,iCAAiC;AACjC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAA;AAE1B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport chalk from 'chalk'\nimport * as console from './console.js'\nimport './exports.js'\nimport pkg from './package.js'\n\nconst { exports: exp, tshy } = pkg\n\nconsole.debug(chalk.yellow.bold('building'), process.cwd())\nconsole.debug(chalk.cyan.dim('tshy config'), tshy)\nconsole.debug(chalk.cyan.dim('exports'), exp)\n\n// have our config, time to build\nawait import('./build.js')\n\nconsole.log(chalk.bold.green('success!'))\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,cAAc,CAAA;AACrB,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;AAElC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;AAC3D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC,CAAA;AAClD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAA;AAE7C,KAAK,EAAE,CAAA;AAEP,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport chalk from 'chalk'\nimport * as console from './console.js'\nimport './exports.js'\nimport pkg from './package.js'\nimport build from './build.js'\n\nconst { exports: exp, tshy } = pkg\n\nconsole.debug(chalk.yellow.bold('building'), process.cwd())\nconsole.debug(chalk.cyan.dim('tshy config'), tshy)\nconsole.debug(chalk.cyan.dim('exports'), exp)\n\nbuild()\n\nconsole.log(chalk.bold.green('success!'))\n"]}
@@ -1,4 +1,4 @@
1
1
  import { Package } from './types.js';
2
- declare const pkg: Package;
3
- export default pkg;
2
+ declare const _default: Package;
3
+ export default _default;
4
4
  //# sourceMappingURL=package.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAWpC,QAAA,MAAM,GAAG,SAAY,CAAA;AAErB,eAAe,GAAG,CAAA"}
1
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;;AAcpC,wBAAwB"}
@@ -1,16 +1,14 @@
1
1
  // get the package.json data for the cwd
2
2
  import { readFileSync } from 'fs';
3
- import { fail } from './fail.js';
3
+ import fail from './fail.js';
4
4
  const readPkg = () => {
5
5
  try {
6
- return JSON.parse(readFileSync('package.json', 'utf8'));
6
+ return Object.assign(JSON.parse(readFileSync('package.json', 'utf8')), { type: 'module' });
7
7
  }
8
8
  catch (er) {
9
9
  fail('failed to read package.json', er);
10
10
  process.exit(1);
11
11
  }
12
12
  };
13
- const pkg = readPkg();
14
- pkg.type = 'module';
15
- export default pkg;
13
+ export default readPkg();
16
14
  //# sourceMappingURL=package.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,MAAM,OAAO,GAAG,GAAY,EAAE;IAC5B,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAA;KACxD;IAAC,OAAO,EAAE,EAAE;QACX,IAAI,CAAC,6BAA6B,EAAE,EAAW,CAAC,CAAA;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAED,MAAM,GAAG,GAAG,OAAO,EAAE,CAAA;AACrB,GAAG,CAAC,IAAI,GAAG,QAAQ,CAAA;AACnB,eAAe,GAAG,CAAA","sourcesContent":["// get the package.json data for the cwd\n\nimport { readFileSync } from 'fs'\nimport { fail } from './fail.js'\nimport { Package } from './types.js'\n\nconst readPkg = (): Package => {\n try {\n return JSON.parse(readFileSync('package.json', 'utf8'))\n } catch (er) {\n fail('failed to read package.json', er as Error)\n process.exit(1)\n }\n}\n\nconst pkg = readPkg()\npkg.type = 'module'\nexport default pkg\n"]}
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,MAAM,OAAO,GAAG,GAAY,EAAE;IAC5B,IAAI;QACF,OAAO,MAAM,CAAC,MAAM,CAClB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,EAChD,EAAE,IAAI,EAAE,QAAQ,EAAE,CACnB,CAAA;KACF;IAAC,OAAO,EAAE,EAAE;QACX,IAAI,CAAC,6BAA6B,EAAE,EAAW,CAAC,CAAA;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAED,eAAe,OAAO,EAAE,CAAA","sourcesContent":["// get the package.json data for the cwd\n\nimport { readFileSync } from 'fs'\nimport fail from './fail.js'\nimport { Package } from './types.js'\n\nconst readPkg = (): Package => {\n try {\n return Object.assign(\n JSON.parse(readFileSync('package.json', 'utf8')),\n { type: 'module' }\n )\n } catch (er) {\n fail('failed to read package.json', er as Error)\n process.exit(1)\n }\n}\n\nexport default readPkg()\n"]}
@@ -1,2 +1,2 @@
1
- export declare const resolveExport: (exp: any, t: 'import' | 'require') => string | undefined;
1
+ export declare const resolveExport: (exp: any, m: 'import' | 'require') => 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,KACL,QAAQ,GAAG,SAAS,KACtB,MAAM,GAAG,SAaX,CAAA"}
1
+ {"version":3,"file":"resolve-export.d.ts","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QACnB,GAAG,KACL,QAAQ,GAAG,SAAS,KACtB,MAAM,GAAG,SAAS,GAAG,IAcvB,CAAA"}
@@ -1,21 +1,23 @@
1
- export const resolveExport = (exp, t) => {
1
+ export const resolveExport = (exp, m) => {
2
2
  if (typeof exp === 'string')
3
3
  return exp;
4
- if (!exp || typeof exp !== 'object')
4
+ if (typeof exp !== 'object')
5
5
  return undefined;
6
+ if (exp === null)
7
+ return exp;
6
8
  if (Array.isArray(exp)) {
7
9
  for (const e of exp) {
8
- const u = resolveExport(e, t);
9
- if (u)
10
+ const u = resolveExport(e, m);
11
+ if (u || u === null)
10
12
  return u;
11
13
  }
12
14
  return undefined;
13
15
  }
14
- if (exp[t])
15
- return resolveExport(exp[t], t);
16
+ if (exp[m])
17
+ return resolveExport(exp[m], m);
16
18
  if (exp.node)
17
- return resolveExport(exp.node, t);
19
+ return resolveExport(exp.node, m);
18
20
  if (exp.default)
19
- return resolveExport(exp.default, t);
21
+ return resolveExport(exp.default, m);
20
22
  };
21
23
  //# sourceMappingURL=resolve-export.js.map
@@ -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,CAAuB,EACH,EAAE;IACtB,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAA;IACvC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;YACnB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAC7B,IAAI,CAAC;gBAAE,OAAO,CAAC,CAAA;SAChB;QACD,OAAO,SAAS,CAAA;KACjB;IACD,IAAI,GAAG,CAAC,CAAC,CAAC;QAAE,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC3C,IAAI,GAAG,CAAC,IAAI;QAAE,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IAC/C,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AACvD,CAAC,CAAA","sourcesContent":["export const resolveExport = (\n exp: any,\n t: 'import' | 'require'\n): string | undefined => {\n if (typeof exp === 'string') return exp\n if (!exp || typeof exp !== 'object') return undefined\n if (Array.isArray(exp)) {\n for (const e of exp) {\n const u = resolveExport(e, t)\n if (u) return u\n }\n return undefined\n }\n if (exp[t]) return resolveExport(exp[t], t)\n if (exp.node) return resolveExport(exp.node, t)\n if (exp.default) return resolveExport(exp.default, t)\n}\n"]}
1
+ {"version":3,"file":"resolve-export.js","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,CAAuB,EACI,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,CAAC,CAAC,CAAA;YAC7B,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;gBAAE,OAAO,CAAC,CAAA;SAC9B;QACD,OAAO,SAAS,CAAA;KACjB;IACD,IAAI,GAAG,CAAC,CAAC,CAAC;QAAE,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC3C,IAAI,GAAG,CAAC,IAAI;QAAE,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IAC/C,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AACvD,CAAC,CAAA","sourcesContent":["export const resolveExport = (\n exp: any,\n m: 'import' | 'require'\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, m)\n if (u || u === null) return u\n }\n return undefined\n }\n if (exp[m]) return resolveExport(exp[m], m)\n if (exp.node) return resolveExport(exp.node, m)\n if (exp.default) return resolveExport(exp.default, m)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"set-folder-dialect.d.ts","sourceRoot":"","sources":["../../src/set-folder-dialect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;gCAcb,MAAM,SAAS,OAAO;AAA7C,wBAGC"}
1
+ {"version":3,"file":"set-folder-dialect.d.ts","sourceRoot":"","sources":["../../src/set-folder-dialect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;gCAcb,MAAM,SAAS,OAAO;AAA7C,wBAIC"}
@@ -1 +1 @@
1
- {"version":3,"file":"set-folder-dialect.js","sourceRoot":"","sources":["../../src/set-folder-dialect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,IAAc,EAAE,EAAE,CACnD,IAAI;IACF,CAAC,CAAC,aAAa,CACX,CAAC,EACD,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ;KAClD,CAAC,CACH;IACH,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;AAEnB,eAAe,CAAC,KAAa,EAAE,IAAc,EAAE,EAAE;IAC/C,IAAI,IAAI;QAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;IACrE,cAAc,CAAC,GAAG,KAAK,eAAe,EAAE,IAAI,CAAC,CAAA;AAC/C,CAAC,CAAA","sourcesContent":["import { writeFileSync } from 'fs'\nimport { rimrafSync } from 'rimraf'\nimport { Dialect } from './types.js'\nimport * as console from './console.js'\nimport chalk from 'chalk'\n\nconst writeDialectPJ = (f: string, mode?: Dialect) =>\n mode\n ? writeFileSync(\n f,\n JSON.stringify({\n type: mode === 'commonjs' ? 'commonjs' : 'module',\n })\n )\n : rimrafSync(f)\n\nexport default (where: string, mode?: Dialect) => {\n if (mode) console.debug(chalk.cyan.dim('set dialect'), {where, mode})\n writeDialectPJ(`${where}/package.json`, mode)\n}\n"]}
1
+ {"version":3,"file":"set-folder-dialect.js","sourceRoot":"","sources":["../../src/set-folder-dialect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,IAAc,EAAE,EAAE,CACnD,IAAI;IACF,CAAC,CAAC,aAAa,CACX,CAAC,EACD,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ;KAClD,CAAC,CACH;IACH,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;AAEnB,eAAe,CAAC,KAAa,EAAE,IAAc,EAAE,EAAE;IAC/C,IAAI,IAAI;QACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/D,cAAc,CAAC,GAAG,KAAK,eAAe,EAAE,IAAI,CAAC,CAAA;AAC/C,CAAC,CAAA","sourcesContent":["import { writeFileSync } from 'fs'\nimport { rimrafSync } from 'rimraf'\nimport { Dialect } from './types.js'\nimport * as console from './console.js'\nimport chalk from 'chalk'\n\nconst writeDialectPJ = (f: string, mode?: Dialect) =>\n mode\n ? writeFileSync(\n f,\n JSON.stringify({\n type: mode === 'commonjs' ? 'commonjs' : 'module',\n })\n )\n : rimrafSync(f)\n\nexport default (where: string, mode?: Dialect) => {\n if (mode)\n console.debug(chalk.cyan.dim('set dialect'), { where, mode })\n writeDialectPJ(`${where}/package.json`, mode)\n}\n"]}
@@ -29,7 +29,7 @@ export type Package = {
29
29
  version: string;
30
30
  type?: 'module';
31
31
  bin?: string | Record<string, string>;
32
- exports: Record<string, Export>;
32
+ exports?: Record<string, Export>;
33
33
  tshy?: Tsh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AAA;CACvB,GAAG,CAAC;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC,CAAC,CAAA;AAE/D,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB,CAAA;AAID,MAAM,MAAM,MAAM,GACd,MAAM,GACN;IACE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GACD;IACE,MAAM,CAAC,EACH,MAAM,GACN;QACE,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACL,OAAO,CAAC,EACJ,MAAM,GACN;QACE,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACN,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type TshyConfig = {\n exports?: Record<string, TshyExport>\n dialects?: Dialect[]\n}\n\nexport type Dialect = 'commonjs' | 'esm'\n\nexport type ExportDetail = {\n default: string\n [k: string]: string\n}\n\nexport type TshyExport =\n | string\n | ({ types?: string; import?: string; require?: string } & (\n | { import: string }\n | { require: string }\n ))\n | ({\n types?: string\n import?: ExportDetail\n require?: ExportDetail\n } & ({ import: ExportDetail } | { require: ExportDetail }))\n\nexport type Package = {\n name: string\n version: string\n type?: 'module'\n bin?: string | Record<string, string>\n exports: Record<string, Export>\n tshy?: TshyConfig\n [k: string]: any\n}\n\n// VERY limited subset of the datatypes \"exports\" can be\n// but we're only writing our flavor, so it's fine.\nexport type Export =\n | string\n | {\n import?: Export\n require?: Export\n types?: Export\n default?: Export\n }\n | {\n import?:\n | string\n | {\n types: string\n default: string\n }\n require?:\n | string\n | {\n types: string\n default: string\n }\n }\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type TshyConfig = {\n exports?: Record<string, TshyExport>\n dialects?: Dialect[]\n}\n\nexport type Dialect = 'commonjs' | 'esm'\n\nexport type ExportDetail = {\n default: string\n [k: string]: string\n}\n\nexport type TshyExport =\n | string\n | ({ types?: string; import?: string; require?: string } & (\n | { import: string }\n | { require: string }\n ))\n | ({\n types?: string\n import?: ExportDetail\n require?: ExportDetail\n } & ({ import: ExportDetail } | { require: ExportDetail }))\n\nexport type Package = {\n name: string\n version: string\n type?: 'module'\n bin?: string | Record<string, string>\n exports?: Record<string, Export>\n tshy?: TshyConfig\n [k: string]: any\n}\n\n// VERY limited subset of the datatypes \"exports\" can be\n// but we're only writing our flavor, so it's fine.\nexport type Export =\n | string\n | {\n import?: Export\n require?: Export\n types?: Export\n default?: Export\n }\n | {\n import?:\n | string\n | {\n types: string\n default: string\n }\n require?:\n | string\n | {\n types: string\n default: string\n }\n }\n"]}
@@ -0,0 +1,4 @@
1
+ import { Dialect } from './types.js';
2
+ declare const _default: (d: any) => d is Dialect[];
3
+ export default _default;
4
+ //# sourceMappingURL=valid-dialects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valid-dialects.d.ts","sourceRoot":"","sources":["../../src/valid-dialects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAA;4BAM3C,GAAG;AADR,wBAiBC"}
@@ -0,0 +1,14 @@
1
+ import fail from './fail.js';
2
+ const isDialect = (d) => d === 'commonjs' || d === 'esm';
3
+ export default (d) => {
4
+ if (!!d &&
5
+ Array.isArray(d) &&
6
+ d.length &&
7
+ !d.some(d => !isDialect(d))) {
8
+ return true;
9
+ }
10
+ fail(`tshy.dialects must be an array including "esm" and/or "commonjs", ` +
11
+ `got: ${JSON.stringify(d)}`);
12
+ return process.exit(1);
13
+ };
14
+ //# sourceMappingURL=valid-dialects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valid-dialects.js","sourceRoot":"","sources":["../../src/valid-dialects.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,MAAM,SAAS,GAAG,CAAC,CAAM,EAAgB,EAAE,CACzC,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,KAAK,CAAA;AAEjC,eAAe,CACb,CAAM,EAC2C,EAAE;IACnD,IACE,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAChB,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC3B;QACA,OAAO,IAAI,CAAA;KACZ;IAED,IAAI,CACF,oEAAoE;QAClE,QAAQ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAC9B,CAAA;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACxB,CAAC,CAAA","sourcesContent":["import fail from './fail.js'\nimport { Dialect, TshyConfig } from './types.js'\n\nconst isDialect = (d: any): d is Dialect =>\n d === 'commonjs' || d === 'esm'\n\nexport default (\n d: any\n): d is Exclude<TshyConfig['dialects'], undefined> => {\n if (\n !!d &&\n Array.isArray(d) &&\n d.length &&\n !d.some(d => !isDialect(d))\n ) {\n return true\n }\n\n fail(\n `tshy.dialects must be an array including \"esm\" and/or \"commonjs\", ` +\n `got: ${JSON.stringify(d)}`\n )\n return process.exit(1)\n}\n"]}
@@ -0,0 +1,3 @@
1
+ declare const _default: (e: any) => e is Record<string, import("./types.js").TshyExport>;
2
+ export default _default;
3
+ //# sourceMappingURL=valid-exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valid-exports.d.ts","sourceRoot":"","sources":["../../src/valid-exports.ts"],"names":[],"mappings":"4BAMK,GAAG;AADR,wBAwCC"}
@@ -0,0 +1,34 @@
1
+ import addDot from './add-dot.js';
2
+ import fail from './fail.js';
3
+ import validExternalExport from './valid-external-export.js';
4
+ export default (e) => {
5
+ if (!e || typeof e !== 'object' || Array.isArray(e))
6
+ return false;
7
+ for (const [sub, exp] of Object.entries(e)) {
8
+ if (sub !== '.' && !sub.startsWith('./')) {
9
+ fail(`tshy.exports key must be "." or start with "./", got: ${sub}`);
10
+ return process.exit(1);
11
+ }
12
+ // just a module. either a built export, or a simple unbuilt export
13
+ if (typeof exp === 'string') {
14
+ e[sub] = addDot(exp);
15
+ continue;
16
+ }
17
+ if (typeof exp !== 'object') {
18
+ fail(`tshy.exports ${sub} value must be valid package.json exports value, ` +
19
+ `got: ${JSON.stringify(exp)}`);
20
+ return process.exit(1);
21
+ }
22
+ // can be any valid external export, but the resolution of
23
+ // import and require must NOT be in ./src
24
+ if (!validExternalExport(exp)) {
25
+ fail(`tshy.exports ${sub} unbuilt exports must not be in ./src, ` +
26
+ `and exports in src must be string values. ` +
27
+ `got: ${JSON.stringify(exp)}`);
28
+ return process.exit(1);
29
+ }
30
+ e[sub] = exp;
31
+ }
32
+ return true;
33
+ };
34
+ //# sourceMappingURL=valid-exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valid-exports.js","sourceRoot":"","sources":["../../src/valid-exports.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cAAc,CAAA;AACjC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,mBAAmB,MAAM,4BAA4B,CAAA;AAE5D,eAAe,CACb,CAAM,EAC0C,EAAE;IAClD,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IACjE,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC1C,IAAI,GAAG,KAAK,GAAG,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,mDAAmD;gBACpE,QAAQ,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAChC,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 value, ` +\n `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"]}
@@ -0,0 +1,4 @@
1
+ import { Export } from './types.js';
2
+ declare const _default: (exp: any) => exp is Export;
3
+ export default _default;
4
+ //# sourceMappingURL=valid-external-export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valid-external-export.d.ts","sourceRoot":"","sources":["../../src/valid-external-export.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;8BAEd,GAAG;AAAxB,wBAMC"}
@@ -0,0 +1,12 @@
1
+ import { join } from 'path/posix';
2
+ import { resolveExport } from './resolve-export.js';
3
+ export default (exp) => {
4
+ const i = resolveExport(exp, 'import');
5
+ const r = resolveExport(exp, 'require');
6
+ if (i && join(i).startsWith('src/'))
7
+ return false;
8
+ if (r && join(r).startsWith('src/'))
9
+ return false;
10
+ return true;
11
+ };
12
+ //# sourceMappingURL=valid-external-export.js.map
@@ -0,0 +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;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGnD,eAAe,CAAC,GAAQ,EAAiB,EAAE;IACzC,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IACtC,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IACvC,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 { resolveExport } from './resolve-export.js'\nimport { Export } from './types.js'\n\nexport default (exp: any): exp is Export => {\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tshy",
3
- "version": "1.0.0-3",
3
+ "version": "1.0.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",
@@ -24,7 +24,12 @@
24
24
  "pretest": "npm run prepare",
25
25
  "presnap": "npm run prepare",
26
26
  "format": "prettier --write . --ignore-path ./.prettierignore --cache",
27
- "typedoc": "typedoc"
27
+ "typedoc": "typedoc",
28
+ "test": "tap",
29
+ "snap": "tap"
30
+ },
31
+ "tap": {
32
+ "coverage-map": "map.js"
28
33
  },
29
34
  "engines": {
30
35
  "node": "16 >=16.17 || 18 >=18.16.0 || >=20.6.1"
@@ -41,6 +46,7 @@
41
46
  "devDependencies": {
42
47
  "@types/node": "^20.6.0",
43
48
  "prettier": "^2.8.8",
49
+ "tap": "^18.0.0-26",
44
50
  "typedoc": "^0.25.1"
45
51
  },
46
52
  "prettier": {