tshy
Advanced tools
Comparing version 1.14.0 to 1.14.1
import chalk from 'chalk'; | ||
import { spawnSync } from 'node:child_process'; | ||
import { existsSync, renameSync, unlinkSync } from 'node:fs'; | ||
import { relative, resolve } from 'node:path/posix'; | ||
@@ -8,2 +7,3 @@ import buildFail from './build-fail.js'; | ||
import * as console from './console.js'; | ||
import ifExist from './if-exist.js'; | ||
import polyfills from './polyfills.js'; | ||
@@ -15,4 +15,2 @@ import setFolderDialect from './set-folder-dialect.js'; | ||
const { commonjsDialects = [] } = config; | ||
const unlinkIfExist = (f) => existsSync(f) && unlinkSync(f); | ||
const renameIfExist = (f, to) => existsSync(f) && renameSync(f, to); | ||
export const buildCommonJS = () => { | ||
@@ -36,6 +34,6 @@ setFolderDialect('src', 'commonjs'); | ||
const stemToDtsPath = `${stemTo}.d.ts.map`; | ||
unlinkIfExist(stemToPath); | ||
unlinkIfExist(stemToDtsPath); | ||
renameIfExist(`${stemFrom}.cjs`, `${stemTo}.js`); | ||
renameIfExist(`${stemFrom}.d.cts`, `${stemTo}.d.ts`); | ||
ifExist.unlink(stemToPath); | ||
ifExist.unlink(stemToDtsPath); | ||
ifExist.rename(`${stemFrom}.cjs`, `${stemTo}.js`); | ||
ifExist.rename(`${stemFrom}.d.cts`, `${stemTo}.d.ts`); | ||
} | ||
@@ -42,0 +40,0 @@ console.error(chalk.cyan.bold('built commonjs')); |
import chalk from 'chalk'; | ||
import { spawnSync } from 'node:child_process'; | ||
import { existsSync, renameSync, unlinkSync } from 'node:fs'; | ||
import { relative, resolve } from 'node:path'; | ||
@@ -8,2 +7,3 @@ import buildFail from './build-fail.js'; | ||
import * as console from './console.js'; | ||
import ifExist from './if-exist.js'; | ||
import polyfills from './polyfills.js'; | ||
@@ -13,4 +13,2 @@ import setFolderDialect from './set-folder-dialect.js'; | ||
import tsc from './which-tsc.js'; | ||
const unlinkIfExist = (f) => existsSync(f) && unlinkSync(f); | ||
const renameIfExist = (f, to) => existsSync(f) && renameSync(f, to); | ||
const node = process.execPath; | ||
@@ -34,6 +32,6 @@ const { esmDialects = [] } = config; | ||
const stemTo = resolve(`.tshy-build/${d}`, relative(resolve('src'), resolve(orig))).replace(/\.tsx?$/, ''); | ||
unlinkIfExist(`${stemTo}.js.map`); | ||
unlinkIfExist(`${stemTo}.d.ts.map`); | ||
renameIfExist(`${stemFrom}.mjs`, `${stemTo}.js`); | ||
renameIfExist(`${stemFrom}.d.mts`, `${stemTo}.d.ts`); | ||
ifExist.unlink(`${stemTo}.js.map`); | ||
ifExist.unlink(`${stemTo}.d.ts.map`); | ||
ifExist.rename(`${stemFrom}.mjs`, `${stemTo}.js`); | ||
ifExist.rename(`${stemFrom}.d.mts`, `${stemTo}.d.ts`); | ||
} | ||
@@ -40,0 +38,0 @@ console.error(chalk.cyan.bold('built ' + d)); |
@@ -42,8 +42,9 @@ // get the config and package and stuff | ||
: {}; | ||
const exportsRaw = tshy.exports; | ||
if (typeof exportsRaw === 'string' || Array.isArray(exportsRaw)) { | ||
let exportsConfig = tshy.exports; | ||
if (typeof exportsConfig === 'string' || | ||
Array.isArray(exportsConfig)) { | ||
// Strip off the `./src` prefix and the extension | ||
// exports: "src/**/*.ts" => exports: {"./foo": "./src/foo.ts"} | ||
const exp = {}; | ||
const pattern = exportsRaw; | ||
const pattern = exportsConfig; | ||
const m = parsePattern(pattern); | ||
@@ -66,2 +67,3 @@ for (const e of sources) { | ||
delete tshy.exports; | ||
exportsConfig = undefined; | ||
} | ||
@@ -74,3 +76,3 @@ else { | ||
} | ||
const config = tshy; | ||
const config = { ...tshy }; | ||
const ti = config; | ||
@@ -87,15 +89,19 @@ if (ti.imports) { | ||
validImports(pkg); | ||
pkg.tshy = config; | ||
if (tshy.exports) | ||
return config; | ||
const e = { | ||
'./package.json': './package.json', | ||
}; | ||
for (const i of sources) { | ||
if (/^\.\/src\/index\.[^\.]+$/.test(i)) { | ||
e['.'] = i; | ||
break; | ||
if (!exportsConfig) { | ||
const e = { | ||
'./package.json': './package.json', | ||
}; | ||
for (const i of sources) { | ||
if (/^\.\/src\/index\.[^\.]+$/.test(i)) { | ||
e['.'] = i; | ||
break; | ||
} | ||
} | ||
config.exports = e; | ||
tshy.exports = e; | ||
exportsConfig = e; | ||
} | ||
config.exports = e; | ||
// return the filled out config, but leave the package.json | ||
// exports as they were, as long as they turned out to be valid. | ||
pkg.tshy = { ...tshy, exports: exportsConfig }; | ||
return config; | ||
@@ -102,0 +108,0 @@ }; |
{ | ||
"name": "tshy", | ||
"version": "1.14.0", | ||
"version": "1.14.1", | ||
"description": "TypeScript HYbridizer - Hybrid (CommonJS/ESM) TypeScript node package builder", | ||
@@ -54,3 +54,3 @@ "author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)", | ||
"prettier": "^2.8.8", | ||
"tap": "^18.7.2", | ||
"tap": "^19.2.1", | ||
"typedoc": "^0.25.13" | ||
@@ -57,0 +57,0 @@ }, |
@@ -53,3 +53,3 @@ # tshy - TypeScript HYbridizer | ||
import { createRequire } from 'node:module' | ||
const req = createRequire(import.meta.url) | ||
const require = createRequire(import.meta.url) | ||
@@ -376,6 +376,3 @@ // create an object using the commonjs version | ||
"tshy": { | ||
"exports": [ | ||
"./src/*.ts", | ||
"./src/utils/*.ts" | ||
] | ||
"exports": ["./src/*.ts", "./src/utils/*.ts"] | ||
} | ||
@@ -647,3 +644,3 @@ } | ||
builds entirely, you can add an `exclude` `string[]` field to the | ||
`tshy` object in `package.json`. For example: | ||
`tshy` object in `package.json`. For example: | ||
@@ -797,3 +794,3 @@ ```json | ||
- A `tsconfig.build.json` for compilation, with `"noEmit": | ||
false`. Note that the [caveats](#tsconfigs) above still apply. | ||
false`. Note that the [caveats](#tsconfigs) above still apply. | ||
@@ -800,0 +797,0 @@ ```json |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
188559
151
1454
903
12