Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@knighted/duel",
"version": "4.0.1",
"version": "4.0.2-rc.0",
Comment thread
knightedcodemonkey marked this conversation as resolved.
"description": "TypeScript dual packages.",
"type": "module",
"main": "dist/esm/duel.js",
Expand Down Expand Up @@ -92,7 +92,6 @@
"@knighted/module": "^1.5.0",
"find-up": "^8.0.0",
"get-tsconfig": "^4.13.0",
"glob": "^13.0.6",
"magic-string": "^0.30.21",
"read-package-up": "^12.0.0"
},
Expand Down
19 changes: 13 additions & 6 deletions scripts/clean-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { rm } from 'node:fs/promises'

import { glob } from 'glob'
import { rm, glob } from 'node:fs/promises'

const roots = ['test/__fixtures__']

const run = async () => {
const targets = new Set()
const globOpts = { dot: true, windowsPathsNoEscape: true }

const collect = async pattern => {
const matches = []

for await (const entry of glob(pattern)) {
matches.push(entry)
}

return matches
}

for (const root of roots) {
const caches = await glob(`${root}/**/.duel-cache`, globOpts)
const dists = await glob(`${root}/**/dist`, globOpts)
const caches = await collect(`${root}/**/.duel-cache`)
const dists = await collect(`${root}/**/dist`)

for (const dir of [...caches, ...dists]) {
targets.add(dir)
Expand Down
19 changes: 14 additions & 5 deletions src/duel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { argv } from 'node:process'
import { pathToFileURL } from 'node:url'
import { join, dirname, resolve, relative, sep } from 'node:path'
import { spawn } from 'node:child_process'
import { writeFile, rm, mkdir, cp, access, readdir } from 'node:fs/promises'
import { writeFile, rm, mkdir, cp, access, readdir, glob } from 'node:fs/promises'
import { createHash } from 'node:crypto'
import { performance } from 'node:perf_hooks'

import { glob } from 'glob'
import { findUp } from 'find-up'
import { transform, collectProjectDualPackageHazards } from '@knighted/module'
import { getTsconfig, parseTsconfig } from 'get-tsconfig'
Expand Down Expand Up @@ -68,6 +67,16 @@ const logDiagnostics = (diags, projectDir, hazardAllowlist = null) => {
return hasError
}

const collectGlob = async (pattern, options) => {
const files = []

for await (const file of glob(pattern, options)) {
files.push(file)
}

return files
}

const duel = async args => {
const ctx = await init(args)

Expand Down Expand Up @@ -757,7 +766,7 @@ const duel = async args => {
* Transform ambiguous modules for the target dual build.
* @see https://github.com/microsoft/TypeScript/issues/58658
*/
const toTransform = await glob(
const toTransform = await collectGlob(
`${subDir.replace(/\\/g, '/')}/**/*{.js,.jsx,.ts,.tsx}`,
{
ignore: `${subDir.replace(/\\/g, '/')}/**/node_modules/**`,
Expand Down Expand Up @@ -858,7 +867,7 @@ const duel = async args => {
}
const dualGlob =
dualTarget === 'commonjs' ? '**/*{.js,.cjs,.d.ts}' : '**/*{.js,.mjs,.d.ts}'
const filenames = await glob(
const filenames = await collectGlob(
`${absoluteDualOutDir.replace(/\\/g, '/')}/${dualGlob}`,
{
ignore: `${absoluteDualOutDir.replace(/\\/g, '/')}/**/node_modules/**`,
Expand Down Expand Up @@ -890,7 +899,7 @@ const duel = async args => {
})

if (dirs && originalType === 'commonjs') {
const primaryFiles = await glob(
const primaryFiles = await collectGlob(
`${primaryOutDir.replace(/\\/g, '/')}/**/*{.js,.cjs,.d.ts}`,
{
ignore: `${primaryOutDir.replace(/\\/g, '/')}/**/node_modules/**`,
Expand Down
25 changes: 13 additions & 12 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathToFileURL } from 'node:url'
import { realpath, readFile, writeFile, symlink, rm } from 'node:fs/promises'
import { realpath, readFile, writeFile, symlink, rm, glob } from 'node:fs/promises'
import { existsSync, rmSync } from 'node:fs'
import { spawnSync } from 'node:child_process'
import { cwd, platform } from 'node:process'
Expand All @@ -14,7 +14,6 @@ import {
normalize as normalizePath,
} from 'node:path'

import { glob } from 'glob'
import { findUp } from 'find-up'

const COLORS = {
Expand Down Expand Up @@ -336,7 +335,11 @@ const generateExports = async options => {
}
const baseEntry = baseMap.get(baseKey) ?? {}

baseEntry[kind] = withDot
if (kind === 'types') {
baseEntry.types = baseEntry.types ?? withDot
} else {
baseEntry[kind] = withDot
}
baseMap.set(baseKey, baseEntry)

const subpath = useEntriesSubpaths
Expand All @@ -349,7 +352,9 @@ const generateExports = async options => {

if (mappedSubpath) {
const subEntry = subpathMap.get(mappedSubpath) ?? {}
subEntry.types = useWildcard ? toWildcardValue(withDot) : withDot
const nextType = useWildcard ? toWildcardValue(withDot) : withDot

subEntry.types = subEntry.types ?? nextType
subpathMap.set(mappedSubpath, subEntry)
}

Expand All @@ -364,23 +369,19 @@ const generateExports = async options => {
}
}

const esmFiles = await glob(`${esmRootPosix}/**/*.{js,mjs,d.ts,d.mts}`, {
for await (const file of glob(`${esmRootPosix}/**/*.{js,mjs,d.ts,d.mts}`, {
ignore: esmIgnore,
})

for (const file of esmFiles) {
})) {
if (/\.d\.(ts|mts)$/.test(file)) {
recordPath('types', file, esmRoot)
} else {
recordPath('import', file, esmRoot)
}
}

const cjsFiles = await glob(`${cjsRootPosix}/**/*.{js,cjs,d.ts,d.cts}`, {
for await (const file of glob(`${cjsRootPosix}/**/*.{js,cjs,d.ts,d.cts}`, {
ignore: cjsIgnore,
})

for (const file of cjsFiles) {
})) {
if (/\.d\.(ts|cts)$/.test(file)) {
recordPath('types', file, cjsRoot)
} else {
Expand Down
Loading