-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: #63
- Loading branch information
Showing
15 changed files
with
5,384 additions
and
2,551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import chalk from 'chalk' | ||
import { linkSync, mkdirSync } from 'node:fs' | ||
import { dirname } from 'node:path' | ||
import { relative, resolve } from 'node:path/posix' | ||
import config from './config.js' | ||
import * as console from './console.js' | ||
import ifExist from './if-exist.js' | ||
import polyfills from './polyfills.js' | ||
import setFolderDialect from './set-folder-dialect.js' | ||
import sources from './sources.js' | ||
import './tsconfig.js' | ||
|
||
const { commonjsDialects = [] } = config | ||
|
||
// don't actually do a build, just link files into places. | ||
export const buildLiveCommonJS = () => { | ||
for (const d of ['commonjs', ...commonjsDialects]) { | ||
const pf = polyfills.get(d === 'commonjs' ? 'cjs' : d) | ||
console.debug(chalk.cyan.dim('linking ' + d)) | ||
for (const s of sources) { | ||
const source = s.substring('./src/'.length) | ||
const target = resolve(`.tshy-build/${d}/${source}`) | ||
mkdirSync(dirname(target), { recursive: true }) | ||
linkSync(s, target) | ||
} | ||
setFolderDialect('.tshy-build/' + d, 'commonjs') | ||
for (const [override, orig] of pf?.map.entries() ?? []) { | ||
const stemFrom = resolve( | ||
`.tshy-build/${d}`, | ||
relative(resolve('src'), resolve(override)) | ||
).replace(/\.cts$/, '') | ||
const stemTo = resolve( | ||
`.tshy-build/${d}`, | ||
relative(resolve('src'), resolve(orig)) | ||
).replace(/\.tsx?$/, '') | ||
ifExist.unlink(`${stemTo}.js.map`) | ||
ifExist.unlink(`${stemTo}.d.ts.map`) | ||
ifExist.rename(`${stemFrom}.cjs`, `${stemTo}.js`) | ||
ifExist.rename(`${stemFrom}.d.cts`, `${stemTo}.d.ts`) | ||
} | ||
console.error(chalk.cyan.bold('linked commonjs')) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import chalk from 'chalk' | ||
import { linkSync, mkdirSync } from 'node:fs' | ||
import { dirname, relative, resolve } from 'node:path' | ||
import config from './config.js' | ||
import * as console from './console.js' | ||
import ifExist from './if-exist.js' | ||
import polyfills from './polyfills.js' | ||
import setFolderDialect from './set-folder-dialect.js' | ||
import sources from './sources.js' | ||
import './tsconfig.js' | ||
|
||
const { esmDialects = [] } = config | ||
|
||
export const buildLiveESM = () => { | ||
for (const d of ['esm', ...esmDialects]) { | ||
const pf = polyfills.get(d) | ||
console.debug(chalk.cyan.dim('linking ' + d)) | ||
for (const s of sources) { | ||
const source = s.substring('./src/'.length) | ||
const target = resolve(`.tshy-build/${d}/${source}`) | ||
mkdirSync(dirname(target), { recursive: true }) | ||
linkSync(s, target) | ||
} | ||
setFolderDialect('.tshy-build/' + d, 'esm') | ||
for (const [override, orig] of pf?.map.entries() ?? []) { | ||
const stemFrom = resolve( | ||
`.tshy-build/${d}`, | ||
relative(resolve('src'), resolve(override)) | ||
).replace(/\.mts$/, '') | ||
const stemTo = resolve( | ||
`.tshy-build/${d}`, | ||
relative(resolve('src'), resolve(orig)) | ||
).replace(/\.tsx?$/, '') | ||
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`) | ||
} | ||
console.error(chalk.cyan.bold('linked ' + d)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`test/build-live-commonjs.ts > TAP > commonjs live dev build > must match snapshot 1`] = ` | ||
Array [ | ||
"blah-blah.cts", | ||
"blah-cjs.cts", | ||
"blah.ts", | ||
"index.ts", | ||
"package.json", | ||
] | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`test/build-live-esm.ts > TAP > esm live dev build > must match snapshot 1`] = ` | ||
Array [ | ||
"blah-blah.mts", | ||
"blah-cjs.cts", | ||
"blah.ts", | ||
"index.ts", | ||
"package.json", | ||
] | ||
` |
Oops, something went wrong.