-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e7bfed
commit 15a75f6
Showing
2 changed files
with
54 additions
and
1 deletion.
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,52 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { PackageJson as PackageJsonType } from 'type-fest' | ||
import { WORKSPACE_FILTERS, forEachWorkspace } from '../utils/forEachWorkspace' | ||
import { readFiles } from '../utils/readFiles' | ||
|
||
try { | ||
forEachWorkspace(WORKSPACE_FILTERS.PACKAGES, (workspacePath) => { | ||
const packageJsonPath = path.join(workspacePath, 'package.json') | ||
const workspacePackageJson = fs.readFileSync(packageJsonPath, 'utf-8') | ||
|
||
if (!workspacePackageJson) return | ||
|
||
const packageJson = JSON.parse(workspacePackageJson) | ||
const packageJsonMain: PackageJsonType = { | ||
...packageJson, | ||
exports: { | ||
'.': { | ||
import: { | ||
default: `./esm/${packageJson.name}.esm.js`, | ||
types: './esm/index.d.ts' | ||
}, | ||
require: { | ||
default: `./cjs/${packageJson.name}.cjs.js`, | ||
types: './cjs/index.d.ts' | ||
} | ||
} | ||
} | ||
} | ||
const packageJsonEsm: PackageJsonType = { | ||
...packageJson, | ||
type: 'module' | ||
} | ||
const packageJsonCjs: PackageJsonType = { | ||
...packageJson, | ||
type: 'commonjs' | ||
} | ||
|
||
readFiles( | ||
`${workspacePath}/`, | ||
(filename, fileContent) => { | ||
// Replace package.json at root with packageJsonMain | ||
// Move packageJsonEsm <package>.esm.js.map to esm folder | ||
// Move packageJsonCjs and <package>.cjs.js.map to cjs folder | ||
// Move index.d.ts to esm and cjs folder | ||
}, | ||
(error) => { | ||
throw error | ||
} | ||
) | ||
}) | ||
} catch (error) {} |