Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

chore(coil-monrorepo-upkeep): use exports instead of folders #3503

Closed
wants to merge 10 commits into from
1,050 changes: 688 additions & 362 deletions packages/coil-monorepo-upkeep/resources/package-json-schema.json

Large diffs are not rendered by default.

1,108 changes: 887 additions & 221 deletions packages/coil-monorepo-upkeep/resources/tsconfig-schema.json

Large diffs are not rendered by default.

34 changes: 19 additions & 15 deletions packages/coil-monorepo-upkeep/src/commands/doUpKeep/doUpKeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,33 +218,37 @@ function upKeepIDETsConfigPaths(subPackages: LernaListItem[]) {
const packagePath = `packages/${getPackageFolder(li)}`
const path = `${packagePath}/src`
paths[li.name] = [path]
const subPackageJSON = readPackageJSON(`${li.location}/package.json`)
const subPackageJSONPath = `${li.location}/package.json`
const subPackageJSON = readPackageJSON(subPackageJSONPath)
// Handle any @ns/package/derp redirects
if (subPackageJSON.subpackages) {
delete subPackageJSON.exports
const makeEl = (n: string) => ({
default: n,
types: `${n}`
})

const exports = (subPackageJSON.exports = {
'.': makeEl('./build')
} as Record<string, any>)

subPackageJSON.subpackages.forEach(name => {
const subpackageName = `${li.name}/${name}`
console.log(subpackageName, exports)
exports[`./${name}`] = makeEl(`./build/${name}`)

const folderPath = pathModule.join(fromRoot(path), name)
const tsPath = pathModule.join(fromRoot(path), `${name}.ts`)
let isFolder = true
if (existsSync(folderPath)) {
// folder
paths[`${li.name}/${name}`] = [`${path}/${name}`]
paths[subpackageName] = [`${path}/${name}`]
} else if (existsSync(tsPath)) {
isFolder = false
paths[`${li.name}/${name}`] = [`${path}/${name}.ts`]
paths[subpackageName] = [`${path}/${name}.ts`]
} else {
throw new Error()
}
cmd(`rm -rf ${packagePath}/${name}`, { cwd: fromRoot('.') })
cmd(`mkdir ${packagePath}/${name}`, { cwd: fromRoot('.') })

writeFileJSON(`${packagePath}/${name}/package.json`, {
name: `${li.name}/${name}`,
private: true,
version: '0.0.0',
main: `../build/${isFolder ? name : `${name}.js`}`,
types: `../build/${isFolder ? name : `${name}.d.ts`}`
})
})
writePackageJSON(subPackageJSONPath, subPackageJSON)
}
})
tsconfig.compilerOptions.paths = paths
Expand Down
1 change: 1 addition & 0 deletions packages/coil-monorepo-upkeep/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface PackageJSON extends Record<string, string | any> {
types?: string
main?: string
subpackages?: string[]
exports?: Record<string, string | object>
resolutions?: StringMap
upkeep?: {
privatePackages?: boolean
Expand Down
7 changes: 0 additions & 7 deletions packages/webmonetization-wext/content/package.json

This file was deleted.

26 changes: 24 additions & 2 deletions packages/webmonetization-wext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,35 @@
},
"license": "Apache-2.0",
"author": "Coil Team <info@coil.com>",
"exports": {
".": {
"default": "./build",
"types": "./build"
},
"./undecorated": {
"default": "./build/undecorated",
"types": "./build/undecorated"
},
"./services": {
"default": "./build/services",
"types": "./build/services"
},
"./content": {
"default": "./build/content",
"types": "./build/content"
},
"./tokens": {
"default": "./build/tokens",
"types": "./build/tokens"
}
},
"main": "./build",
"types": "./build",
"subpackages": [
"tokens",
"undecorated",
"services",
"content"
"content",
"tokens"
],
"scripts": {
"build:ts": "tsc --build tsconfig.build.json",
Expand Down
7 changes: 0 additions & 7 deletions packages/webmonetization-wext/services/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions packages/webmonetization-wext/tokens/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions packages/webmonetization-wext/undecorated/package.json

This file was deleted.

6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
"@webmonetization/wext": [
"packages/webmonetization-wext/src"
],
"@webmonetization/wext/tokens": [
"packages/webmonetization-wext/src/tokens.ts"
],
"@webmonetization/wext/undecorated": [
"packages/webmonetization-wext/src/undecorated"
],
Expand All @@ -83,6 +80,9 @@
],
"@webmonetization/wext/content": [
"packages/webmonetization-wext/src/content"
],
"@webmonetization/wext/tokens": [
"packages/webmonetization-wext/src/tokens.ts"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

"jsx": "react",
"downlevelIteration": true,
"moduleResolution": "node",
"moduleResolution": "node16",

"isolatedModules": true,

Expand Down