tshy 1.1.0 → 1.2.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 CHANGED
@@ -48,6 +48,8 @@ There is very little configuration for this. The only thing to
48
48
  decide is the exported paths. If you have a `./index.ts` file,
49
49
  then that will be listed as the main `"."` export by default.
50
50
 
51
+ ### `exports`
52
+
51
53
  You can set other entry points by putting this in your
52
54
  `package.json` file:
53
55
 
@@ -111,7 +113,7 @@ just be passed through as-is.
111
113
  }
112
114
  ```
113
115
 
114
- ## Making Noise
116
+ ### Making Noise
115
117
 
116
118
  On failure, all logs will be printed.
117
119
 
@@ -121,7 +123,7 @@ To print error logs and a `success!` message at the end, set
121
123
  To print debugging and other extra information, set
122
124
  `TSHY_VERBOSE=2` in the environment.
123
125
 
124
- ## Selecting Dialects
126
+ ### Selecting Dialects
125
127
 
126
128
  You can tell tshy which dialect you're building for by setting
127
129
  the `dialects` config to an array of strings:
@@ -138,6 +140,77 @@ The default is `["esm", "commonjs"]` (ie, both of them). If you
138
140
  set it to just one, then only that dialect will be built and
139
141
  exported.
140
142
 
143
+ ### Suppressing the self-link
144
+
145
+ See below about **Local Package `exports`** for an explanation of
146
+ what this is.
147
+
148
+ Suppress the symlink to the project folder into a `node_modules`
149
+ folder in `dist` and `src` by doing this:
150
+
151
+ ```json
152
+ {
153
+ "tshy": {
154
+ "selfLink": false
155
+ }
156
+ }
157
+ ```
158
+
159
+ ### Old Style Exports
160
+
161
+ Versions of node prior to 12.10.0 (published in early to mid
162
+ 2016) did not have support for `exports` as a means for defining
163
+ package entry points.
164
+
165
+ By default, tshy deletes the `main` field, rather than maintain
166
+ this affordance for versions of node that met their end of life
167
+ more than a year ago. However, some tools still rely on `main`
168
+ and have not been updated to read the package entry points via
169
+ `exports`.
170
+
171
+ You can tell tshy to export a top-level `main` and `types` field
172
+ by setting `main` to either `commonjs` or `esm`. If `main` is set
173
+ to `"commonjs"`, then the package will not have `"type":
174
+ "module"` set.
175
+
176
+ If the specified dialect is not built, or if a `"."` export is
177
+ not created, or if the `"."` export does not support the
178
+ specified dialect, then the build will fail.
179
+
180
+ For example, this config:
181
+
182
+ ```json
183
+ {
184
+ "tshy": {
185
+ "exports": {
186
+ ".": "./src/index.ts"
187
+ },
188
+ "main": "commonjs"
189
+ }
190
+ }
191
+ ```
192
+
193
+ will produce:
194
+
195
+ ```json
196
+ {
197
+ "main": "./dist/commonjs/index.js",
198
+ "types": "./dist/commonjs/index.d.ts",
199
+ "exports": {
200
+ ".": {
201
+ "require": {
202
+ "types": "./dist/commonjs/index.d.ts",
203
+ "default": "./dist/commonjs/index.js"
204
+ },
205
+ "import": {
206
+ "types": "./dist/esm/index.d.ts",
207
+ "default": "./dist/esm/index.js"
208
+ }
209
+ }
210
+ }
211
+ }
212
+ ```
213
+
141
214
  ## CommonJS Dialect Polyfills
142
215
 
143
216
  Sometimes you have to do something in different ways depending on
@@ -299,6 +372,18 @@ If you rely on this feature, you may need to add a `paths`
299
372
  section to your `tsconfig.json` so that you don't get nagged
300
373
  constantly by your editor about missing type references.
301
374
 
375
+ You can suppress the self-linking by putting this config in
376
+ `package.json` but be advised this means that you won't be able
377
+ to import from local package exports:
378
+
379
+ ```json
380
+ {
381
+ "tshy": {
382
+ "selfLink": false
383
+ }
384
+ }
385
+ ```
386
+
302
387
  <details>
303
388
  <summary>tl;dr explanation</summary>
304
389
 
@@ -1 +1 @@
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
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;AA+BhD,QAAA,MAAM,MAAM,EAAE,UAAoC,CAAA;AAClD,eAAe,MAAM,CAAA"}
@@ -6,7 +6,8 @@ import validExports from './valid-exports.js';
6
6
  const validConfig = (e) => !!e &&
7
7
  typeof e === 'object' &&
8
8
  (e.exports === undefined || validExports(e['exports'])) &&
9
- (e.dialects === undefined || validDialects(e['dialects']));
9
+ (e.dialects === undefined || validDialects(e['dialects'])) &&
10
+ (e.selfLink === undefined || typeof e.selfLink === 'boolean');
10
11
  const getConfig = (pkg, sources) => {
11
12
  const tshy = validConfig(pkg.tshy) ? pkg.tshy : {};
12
13
  if (tshy.exports)
@@ -1 +1 @@
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
+ {"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;IAC1D,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAA;AAE/D,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 (e.selfLink === undefined || typeof e.selfLink === 'boolean')\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,7 +1,11 @@
1
- import { Export, TshyConfig, TshyExport } from './types.js';
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { Export, Package, TshyConfig, TshyExport } from './types.js';
2
3
  export declare const getImpTarget: (s: string | TshyExport | undefined | null) => string | undefined | null;
3
4
  export declare const getReqTarget: (s: string | TshyExport | undefined | null, polyfills: Map<string, string>) => string | null | undefined;
4
5
  export declare const getExports: (c: TshyConfig, polyfills: Map<string, string>) => Record<string, Export>;
6
+ export declare const setMain: (c: TshyConfig | undefined, pkg: Package & {
7
+ exports: Record<string, Export>;
8
+ }) => undefined;
5
9
  declare const _default: Record<string, Export>;
6
10
  export default _default;
7
11
  //# 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,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
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGpE,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;AAED,eAAO,MAAM,OAAO,MACf,UAAU,GAAG,SAAS,OACpB,OAAO,GAAG;IAAE,SAAS,OAAO,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,cAqBnD,CAAA;;AAMD,wBAA0B"}
@@ -5,6 +5,7 @@ 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
+ import { isDialect } from './valid-dialects.js';
8
9
  export const getImpTarget = (s) => {
9
10
  if (s === undefined)
10
11
  return undefined;
@@ -16,7 +17,7 @@ export const getImpTarget = (s) => {
16
17
  ? `./dist/esm/${relative(resolve('./src'), resolve(imp)).replace(/\.(m?)tsx?$/, '.$1js')}`
17
18
  : undefined;
18
19
  }
19
- return resolveExport(s, 'import');
20
+ return resolveExport(s, ['import']);
20
21
  };
21
22
  export const getReqTarget = (s, polyfills) => {
22
23
  if (s === undefined)
@@ -29,14 +30,14 @@ export const getReqTarget = (s, polyfills) => {
29
30
  ? `./dist/commonjs/${relative(resolve('./src'), resolve(polyfills.get(req) || req)).replace(/\.(c?)tsx?$/, '.$1js')}`
30
31
  : undefined;
31
32
  }
32
- return getReqTarget(resolveExport(s, 'require'), polyfills);
33
+ return getReqTarget(resolveExport(s, ['require']), polyfills);
33
34
  };
34
35
  export const getExports = (c, polyfills) => {
35
36
  // by this time it always exports, will get the default if missing
36
37
  /* c8 ignore start */
37
38
  if (!c.exports) {
38
39
  fail('no exports on tshy config (is there code in ./src?)');
39
- process.exit(1);
40
+ return process.exit(1);
40
41
  }
41
42
  /* c8 ignore stop */
42
43
  const e = {};
@@ -70,9 +71,33 @@ export const getExports = (c, polyfills) => {
70
71
  }
71
72
  return e;
72
73
  };
74
+ export const setMain = (c, pkg) => {
75
+ if (c?.main !== undefined) {
76
+ if (!isDialect(c.main)) {
77
+ fail(`config.main must be 'commonjs' or 'esm', got: ${c.main}`);
78
+ return process.exit(1);
79
+ }
80
+ const m = c.main === 'commonjs' ? 'require' : 'import';
81
+ const mod = resolveExport(pkg.exports['.'], [m]);
82
+ if (!mod) {
83
+ fail(`could not resolve exports['.'] for tshy.main '${m}'`);
84
+ return process.exit(1);
85
+ }
86
+ const types = resolveExport(pkg.exports['.'], [m, 'types']);
87
+ pkg.main = mod;
88
+ if (types && types !== mod)
89
+ pkg.types = types;
90
+ else
91
+ delete pkg.types;
92
+ }
93
+ else {
94
+ delete pkg.main;
95
+ delete pkg.types;
96
+ }
97
+ };
73
98
  // These are all defined by exports, so it's just confusing otherwise
74
99
  delete pkg.module;
75
- delete pkg.main;
76
- delete pkg.types;
77
- export default pkg.exports = getExports(config, polyfills);
100
+ pkg.exports = getExports(config, polyfills);
101
+ setMain(config, pkg);
102
+ export default pkg.exports;
78
103
  //# sourceMappingURL=exports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"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C,CAAA;QAE5C,uBAAuB;QACvB,qBAAqB;QACrB,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS;YAAE,SAAQ;QACtC,oBAAoB;QAEpB,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\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
+ {"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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,CAAC,CAAA;QAC3D,GAAG,CAAC,IAAI,GAAG,GAAG,CAAA;QACd,IAAI,KAAK,IAAI,KAAK,KAAK,GAAG;YAAE,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;;YACxC,OAAO,GAAG,CAAC,KAAK,CAAA;KACtB;SAAM;QACL,OAAO,GAAG,CAAC,IAAI,CAAA;QACf,OAAO,GAAG,CAAC,KAAK,CAAA;KACjB;AACH,CAAC,CAAA;AAED,qEAAqE;AACrE,OAAO,GAAG,CAAC,MAAM,CAAA;AACjB,GAAG,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAC3C,OAAO,CAAC,MAAM,EAAE,GAAoD,CAAC,CAAA;AACrE,eAAe,GAAG,CAAC,OAAO,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, Package, TshyConfig, TshyExport } from './types.js'\nimport { isDialect } from './valid-dialects.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 return 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\nexport const setMain = (\n c: TshyConfig | undefined,\n pkg: Package & { exports: Record<string, Export> }\n) => {\n if (c?.main !== undefined) {\n if (!isDialect(c.main)) {\n fail(`config.main must be 'commonjs' or 'esm', got: ${c.main}`)\n return process.exit(1)\n }\n const m = c.main === 'commonjs' ? 'require' : 'import'\n const mod = resolveExport(pkg.exports['.'], [m])\n if (!mod) {\n fail(`could not resolve exports['.'] for tshy.main '${m}'`)\n return process.exit(1)\n }\n const types = resolveExport(pkg.exports['.'], [m, 'types'])\n pkg.main = mod\n if (types && types !== mod) pkg.types = types\n else delete pkg.types\n } else {\n delete pkg.main\n delete pkg.types\n }\n}\n\n// These are all defined by exports, so it's just confusing otherwise\ndelete pkg.module\npkg.exports = getExports(config, polyfills)\nsetMain(config, pkg as Package & { exports: Record<string, Export> })\nexport default pkg.exports\n"]}
@@ -1 +1 @@
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
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;;AAWpC,wBAAwB"}
@@ -3,7 +3,7 @@ import { readFileSync } from 'fs';
3
3
  import fail from './fail.js';
4
4
  const readPkg = () => {
5
5
  try {
6
- return Object.assign(JSON.parse(readFileSync('package.json', 'utf8')), { type: 'module' });
6
+ return JSON.parse(readFileSync('package.json', 'utf8'));
7
7
  }
8
8
  catch (er) {
9
9
  fail('failed to read package.json', er);
@@ -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,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
+ {"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,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,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 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\nexport default readPkg()\n"]}
@@ -1,2 +1,2 @@
1
- export declare const resolveExport: (exp: any, m: 'import' | 'require') => string | undefined | null;
1
+ export declare const resolveExport: (exp: any, conditions: ('import' | 'require' | 'types')[]) => 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,SAAS,GAAG,IAcvB,CAAA"}
1
+ {"version":3,"file":"resolve-export.d.ts","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QACnB,GAAG,cACI,CAAC,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,EAAE,KAC7C,MAAM,GAAG,SAAS,GAAG,IAkBvB,CAAA"}
@@ -1,4 +1,4 @@
1
- export const resolveExport = (exp, m) => {
1
+ export const resolveExport = (exp, conditions) => {
2
2
  if (typeof exp === 'string')
3
3
  return exp;
4
4
  if (typeof exp !== 'object')
@@ -7,17 +7,19 @@ export const resolveExport = (exp, m) => {
7
7
  return exp;
8
8
  if (Array.isArray(exp)) {
9
9
  for (const e of exp) {
10
- const u = resolveExport(e, m);
10
+ const u = resolveExport(e, conditions);
11
11
  if (u || u === null)
12
12
  return u;
13
13
  }
14
14
  return undefined;
15
15
  }
16
- if (exp[m])
17
- return resolveExport(exp[m], m);
18
- if (exp.node)
19
- return resolveExport(exp.node, m);
20
- if (exp.default)
21
- return resolveExport(exp.default, m);
16
+ const conds = [...conditions, 'node', 'default'];
17
+ for (const [c, e] of Object.entries(exp)) {
18
+ if (conds.includes(c)) {
19
+ const u = resolveExport(e, conditions);
20
+ if (u || u === null)
21
+ return u;
22
+ }
23
+ }
22
24
  };
23
25
  //# 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,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
+ {"version":3,"file":"resolve-export.js","sourceRoot":"","sources":["../../src/resolve-export.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,UAA8C,EACnB,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: ('import' | 'require' | 'types')[]\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"self-dep.d.ts","sourceRoot":"","sources":["../../src/self-dep.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAIpC,eAAO,MAAM,IAAI,QAAS,OAAO,SAAS,MAAM,SAQ/C,CAAA;AAED,eAAO,MAAM,MAAM,QAAS,OAAO,SAAS,MAAM,SAMjD,CAAA"}
1
+ {"version":3,"file":"self-dep.d.ts","sourceRoot":"","sources":["../../src/self-dep.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAmCpC,eAAO,MAAM,IAAI,QAAS,OAAO,SAAS,MAAM,SAmB/C,CAAA;AAED,eAAO,MAAM,MAAM,QAAS,OAAO,SAAS,MAAM,SAYjD,CAAA"}
@@ -1,23 +1,63 @@
1
1
  // link the package folder into ./target/node_modules/<pkgname>
2
- import { symlinkSync } from 'fs';
2
+ import { readlinkSync, symlinkSync } from 'fs';
3
3
  import { mkdirpSync } from 'mkdirp';
4
- import { dirname, relative, resolve } from 'path';
4
+ import { dirname, relative, resolve, sep } from 'path';
5
5
  import { rimrafSync } from 'rimraf';
6
+ import { walkUp } from 'walk-up-path';
6
7
  const dirsMade = new Map();
8
+ // if the cwd is in already linked to or living within node_modules,
9
+ // then skip the linking, because it's already done.
10
+ // This is typically the case in a workspaces setup, and
11
+ // creating yet *another* symlink to ourselves in src/node_modules
12
+ // will break nx's change detection logic with an ELOOP error.
13
+ let inNM = undefined;
14
+ const linkedAlready = (pkg) => {
15
+ if (inNM !== undefined) {
16
+ return inNM;
17
+ }
18
+ const cwd = process.cwd();
19
+ const p = `${sep}node_modules${sep}${pkg.name}`.toLowerCase();
20
+ if (cwd.toLowerCase().endsWith(p)) {
21
+ return (inNM = true);
22
+ }
23
+ for (const p of walkUp(cwd)) {
24
+ const link = resolve(p, 'node_modules', pkg.name);
25
+ try {
26
+ const target = resolve(dirname(link), readlinkSync(link));
27
+ if (relative(target, cwd) === '') {
28
+ return (inNM = true);
29
+ }
30
+ }
31
+ catch { }
32
+ }
33
+ return (inNM = false);
34
+ };
7
35
  export const link = (pkg, where) => {
8
- if (!pkg.name)
36
+ if (!pkg.name ||
37
+ pkg?.tshy?.selfLink === false ||
38
+ linkedAlready(pkg)) {
9
39
  return;
40
+ }
10
41
  const dest = resolve(where, 'node_modules', pkg.name);
11
42
  const dir = dirname(dest);
12
43
  const src = relative(dir, process.cwd());
13
44
  const made = mkdirpSync(dir);
14
45
  if (made)
15
46
  dirsMade.set(dest, made);
16
- symlinkSync(src, dest);
47
+ try {
48
+ symlinkSync(src, dest);
49
+ }
50
+ catch {
51
+ rimrafSync(dest);
52
+ symlinkSync(src, dest);
53
+ }
17
54
  };
18
55
  export const unlink = (pkg, where) => {
19
- if (!pkg.name)
56
+ if (!pkg.name ||
57
+ pkg?.tshy?.selfLink === false ||
58
+ linkedAlready(pkg)) {
20
59
  return;
60
+ }
21
61
  const dest = resolve(where, 'node_modules', pkg.name);
22
62
  rimrafSync(dest);
23
63
  const made = dirsMade.get(dest);
@@ -1 +1 @@
1
- {"version":3,"file":"self-dep.js","sourceRoot":"","sources":["../../src/self-dep.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAGnC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;AAE1C,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAY,EAAE,KAAa,EAAE,EAAE;IAClD,IAAI,CAAC,GAAG,CAAC,IAAI;QAAE,OAAM;IACrB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IACxC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,IAAI;QAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAClC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAY,EAAE,KAAa,EAAE,EAAE;IACpD,IAAI,CAAC,GAAG,CAAC,IAAI;QAAE,OAAM;IACrB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IACrD,UAAU,CAAC,IAAI,CAAC,CAAA;IAChB,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,IAAI;QAAE,UAAU,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["// link the package folder into ./target/node_modules/<pkgname>\nimport { symlinkSync } from 'fs'\nimport { mkdirpSync } from 'mkdirp'\nimport { dirname, relative, resolve } from 'path'\nimport { rimrafSync } from 'rimraf'\nimport { Package } from './types.js'\n\nconst dirsMade = new Map<string, string>()\n\nexport const link = (pkg: Package, where: string) => {\n if (!pkg.name) return\n const dest = resolve(where, 'node_modules', pkg.name)\n const dir = dirname(dest)\n const src = relative(dir, process.cwd())\n const made = mkdirpSync(dir)\n if (made) dirsMade.set(dest, made)\n symlinkSync(src, dest)\n}\n\nexport const unlink = (pkg: Package, where: string) => {\n if (!pkg.name) return\n const dest = resolve(where, 'node_modules', pkg.name)\n rimrafSync(dest)\n const made = dirsMade.get(dest)\n if (made) rimrafSync(made)\n}\n"]}
1
+ {"version":3,"file":"self-dep.js","sourceRoot":"","sources":["../../src/self-dep.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAGrC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;AAE1C,oEAAoE;AACpE,oDAAoD;AACpD,wDAAwD;AACxD,kEAAkE;AAClE,8DAA8D;AAC9D,I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O,CAAC,IAAI,CAAC,CAAA;IACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IACxC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,IAAI;QAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAClC,IAAI;QACF,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;KACvB;IAAC,MAAM;QACN,UAAU,CAAC,IAAI,CAAC,CAAA;QAChB,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;KACvB;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAY,EAAE,KAAa,EAAE,EAAE;IACpD,IACE,CAAC,GAAG,CAAC,IAAI;QACT,GAAG,EAAE,IAAI,EAAE,QAAQ,KAAK,KAAK;QAC7B,aAAa,CAAC,GAAG,CAAC,EAClB;QACA,OAAM;KACP;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IACrD,UAAU,CAAC,IAAI,CAAC,CAAA;IAChB,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,IAAI;QAAE,UAAU,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["// link the package folder into ./target/node_modules/<pkgname>\nimport { readlinkSync, symlinkSync } from 'fs'\nimport { mkdirpSync } from 'mkdirp'\nimport { dirname, relative, resolve, sep } from 'path'\nimport { rimrafSync } from 'rimraf'\nimport { walkUp } from 'walk-up-path'\nimport { Package } from './types.js'\n\nconst dirsMade = new Map<string, string>()\n\n// if the cwd is in already linked to or living within node_modules,\n// then skip the linking, because it's already done.\n// This is typically the case in a workspaces setup, and\n// creating yet *another* symlink to ourselves in src/node_modules\n// will break nx's change detection logic with an ELOOP error.\nlet inNM: boolean | undefined = undefined\n\nconst linkedAlready = (pkg: Package) => {\n if (inNM !== undefined) {\n return inNM\n }\n\n const cwd = process.cwd()\n const p = `${sep}node_modules${sep}${pkg.name}`.toLowerCase()\n if (cwd.toLowerCase().endsWith(p)) {\n return (inNM = true)\n }\n\n for (const p of walkUp(cwd)) {\n const link = resolve(p, 'node_modules', pkg.name)\n try {\n const target = resolve(dirname(link), readlinkSync(link))\n if (relative(target, cwd) === '') {\n return (inNM = true)\n }\n } catch {}\n }\n\n return (inNM = false)\n}\n\nexport const link = (pkg: Package, where: string) => {\n if (\n !pkg.name ||\n pkg?.tshy?.selfLink === false ||\n linkedAlready(pkg)\n ) {\n return\n }\n const dest = resolve(where, 'node_modules', pkg.name)\n const dir = dirname(dest)\n const src = relative(dir, process.cwd())\n const made = mkdirpSync(dir)\n if (made) dirsMade.set(dest, made)\n try {\n symlinkSync(src, dest)\n } catch {\n rimrafSync(dest)\n symlinkSync(src, dest)\n }\n}\n\nexport const unlink = (pkg: Package, where: string) => {\n if (\n !pkg.name ||\n pkg?.tshy?.selfLink === false ||\n linkedAlready(pkg)\n ) {\n return\n }\n const dest = resolve(where, 'node_modules', pkg.name)\n rimrafSync(dest)\n const made = dirsMade.get(dest)\n if (made) rimrafSync(made)\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  export type TshyConfig = {
2
2
  exports?: Record<string, TshyExport>;
3
3
  dialects?: Dialect[];
4
+ selfLink?: boolean;
5
+ main?: Dialect;
4
6
  };
5
7
  export type Dialect = 'commonjs' | 'esm';
6
8
  export type ExportDetail = {
@@ -27,6 +29,8 @@ export type TshyExport = string | ({
27
29
  export type Package = {
28
30
  name: string;
29
31
  version: string;
32
+ main?: string;
33
+ types?: string;
30
34
  type?: 'module';
31
35
  bin?: string | Record<string, string>;
32
36
  exports?: Record<string, Export>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAA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rB,OAAO,CAAC,EAAE,YAAY,CAAA;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,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,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,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;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 imports?: Record<string, any>\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 selfLink?: boolean\n main?: 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 main?: string\n types?: string\n type?: 'module'\n bin?: string | Record<string, string>\n exports?: Record<string, Export>\n tshy?: TshyConfig\n imports?: Record<string, any>\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,4 +1,5 @@
1
1
  import { Dialect } from './types.js';
2
+ export declare const isDialect: (d: any) => d is Dialect;
2
3
  declare const _default: (d: any) => d is Dialect[];
3
4
  export default _default;
4
5
  //# sourceMappingURL=valid-dialects.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"valid-dialects.d.ts","sourceRoot":"","sources":["../../src/valid-dialects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAA;AAEhD,eAAO,MAAM,SAAS,MAAO,GAAG,iBACC,CAAA;4BAG5B,GAAG;AADR,wBAiBC"}
@@ -1,5 +1,5 @@
1
1
  import fail from './fail.js';
2
- const isDialect = (d) => d === 'commonjs' || d === 'esm';
2
+ export const isDialect = (d) => d === 'commonjs' || d === 'esm';
3
3
  export default (d) => {
4
4
  if (!!d &&
5
5
  Array.isArray(d) &&
@@ -1 +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"]}
1
+ {"version":3,"file":"valid-dialects.js","sourceRoot":"","sources":["../../src/valid-dialects.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAM,EAAgB,EAAE,CAChD,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\nexport const 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"]}
@@ -1,8 +1,8 @@
1
1
  import { join } from 'path/posix';
2
2
  import { resolveExport } from './resolve-export.js';
3
3
  export default (exp) => {
4
- const i = resolveExport(exp, 'import');
5
- const r = resolveExport(exp, 'require');
4
+ const i = resolveExport(exp, ['import']);
5
+ const r = resolveExport(exp, ['require']);
6
6
  if (i && join(i).startsWith('src/'))
7
7
  return false;
8
8
  if (r && join(r).startsWith('src/'))
@@ -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;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"]}
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,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 { 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.1.0",
3
+ "version": "1.2.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",
@@ -16,7 +16,8 @@
16
16
  "resolve-import": "^1.4.1",
17
17
  "rimraf": "^5.0.1",
18
18
  "sync-content": "^1.0.2",
19
- "typescript": "5.2"
19
+ "typescript": "5.2",
20
+ "walk-up-path": "^3.0.1"
20
21
  },
21
22
  "scripts": {
22
23
  "postversion": "npm publish",