Skip to content

Commit

Permalink
Scaffold nodenext support script.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjerleke committed Oct 11, 2023
1 parent 0e7bfed commit 15a75f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
"start": "yarn workspace embla-carousel-docs run start",
"start:vanilla": "npm-run-all --parallel watch:package-vanilla watch:playground-vanilla",
"start:react": "npm-run-all --parallel watch:package-vanilla watch:package-react watch:playground-react",
"build": "npm-run-all build:packages build:package-readmes format",
"build": "npm-run-all build:packages build:package-readmes build:package-nodenext format",
"build:packages": "yarn workspaces foreach -vt --exclude \"{embla-carousel-monorepo,embla-carousel-playground-vanilla,embla-carousel-playground-react}\" run build",
"build:package-readmes": "npx ts-node --project scripts/tsconfig.node.json scripts/create-readmes/index.ts --templatePath=scripts/create-readmes/readme-template.md",
"build:package-nodenext": "npx ts-node --project scripts/tsconfig.node.json scripts/create-nodenext-support/index.ts",
"build:docs": "yarn workspace embla-carousel-docs run predeploy",
"eslint:report": "yarn workspaces foreach -v --exclude \"{embla-carousel-monorepo,embla-carousel-playground-vanilla,embla-carousel-playground-react}\" run eslint:report",
"prettier:report": "prettier \"**/*.{js,jsx,tsx,ts,scss,json}\" --check",
Expand Down
52 changes: 52 additions & 0 deletions scripts/create-nodenext-support/index.ts
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) {}

0 comments on commit 15a75f6

Please sign in to comment.