-
Notifications
You must be signed in to change notification settings - Fork 36
WIP: Output .mjs for hybrid packages #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
72636c
wants to merge
10
commits into
main
Choose a base branch
from
cjs-mjs-output
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
36fb064
Spaghetti the code
72636c 79e60c4
Dogfood
72636c 1ba479e
Revert "Dogfood"
72636c 3ed773a
Output regular .js for CommonJS
72636c 8944cb5
Bundle with `packages: 'external'`
72636c d42516a
Reduce duplication
72636c 61a8f77
Default declarations to `removeComments: false`
72636c 04aa3b2
Infer `declaration` on `build-package`
72636c 1d43db2
Merge branch 'main' into cjs-mjs-output
72636c 2c2b04b
Reduce duplication further
72636c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,58 +1,26 @@ | ||
| import chalk from 'chalk'; | ||
|
|
||
| import { hasDebugFlag } from '../../utils/args'; | ||
| import { log } from '../../utils/logging'; | ||
| import { getStringPropFromConsumerManifest } from '../../utils/manifest'; | ||
|
|
||
| import { copyAssets } from './assets'; | ||
| import { esbuild } from './esbuild'; | ||
| import { readTsconfig, tsc } from './tsc'; | ||
|
|
||
| export const build = async (args = process.argv.slice(2)) => { | ||
| // TODO: define a unified `package.json#/skuba` schema and parser so we don't | ||
| // need all these messy lookups. | ||
| const tool = await getStringPropFromConsumerManifest('build'); | ||
|
|
||
| switch (tool) { | ||
| case 'esbuild': { | ||
| const debug = hasDebugFlag(args); | ||
|
|
||
| log.plain(chalk.yellow('esbuild')); | ||
| await esbuild({ debug }, args); | ||
| break; | ||
| } | ||
|
|
||
| // TODO: flip the default case over to `esbuild` in skuba vNext. | ||
| case undefined: | ||
| case 'tsc': { | ||
| log.plain(chalk.blue('tsc')); | ||
| await tsc(args); | ||
| break; | ||
| } | ||
|
|
||
| default: { | ||
| log.err( | ||
| 'We don’t support the build tool specified in your', | ||
| log.bold('package.json'), | ||
| 'yet:', | ||
| ); | ||
| log.err(log.subtle(JSON.stringify({ skuba: { build: tool } }, null, 2))); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| const parsedCommandLine = readTsconfig(args, log); | ||
|
|
||
| if (!parsedCommandLine || process.exitCode) { | ||
| return; | ||
| } | ||
|
|
||
| const { options: compilerOptions } = parsedCommandLine; | ||
|
|
||
| if (!compilerOptions.outDir) { | ||
| return; | ||
| } | ||
|
|
||
| await copyAssets(compilerOptions.outDir); | ||
| }; | ||
| import { runBuildTool } from './runner'; | ||
| import { tsc } from './tsc'; | ||
|
|
||
| export const build = async (args = process.argv.slice(2)) => | ||
| runBuildTool( | ||
| { | ||
| esbuild: async ({ compilerOptions, ...params }) => { | ||
| await esbuild({ ...params, compilerOptions, mode: 'build' }, args); | ||
|
|
||
| if (compilerOptions.outDir) { | ||
| await copyAssets(compilerOptions.outDir); | ||
| } | ||
| }, | ||
|
|
||
| tsc: async ({ compilerOptions }) => { | ||
| await tsc(args); | ||
|
|
||
| if (compilerOptions.outDir) { | ||
| await copyAssets(compilerOptions.outDir); | ||
| } | ||
| }, | ||
| }, | ||
| args, | ||
| ); |
This file contains hidden or 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,68 @@ | ||
| import chalk from 'chalk'; | ||
| import type { CompilerOptions } from 'typescript'; | ||
|
|
||
| import { hasDebugFlag } from '../../utils/args'; | ||
| import { type Logger, createLogger } from '../../utils/logging'; | ||
| import { getStringPropFromConsumerManifest } from '../../utils/manifest'; | ||
|
|
||
| import { readTsconfig } from './tsc'; | ||
|
|
||
| export type RunnerParams = { | ||
| compilerOptions: CompilerOptions; | ||
| debug: boolean; | ||
| entryPoints: string[]; | ||
| log: Logger; | ||
| }; | ||
|
|
||
| type RunBuildToolParams = { | ||
| esbuild: (params: RunnerParams, args: string[]) => Promise<void>; | ||
| tsc: (params: RunnerParams, args: string[]) => Promise<void>; | ||
| }; | ||
|
|
||
| export const runBuildTool = async (run: RunBuildToolParams, args: string[]) => { | ||
| const debug = hasDebugFlag(args); | ||
|
|
||
| const log = createLogger(debug); | ||
|
|
||
| const tsconfig = readTsconfig(args, log); | ||
|
|
||
| if (!tsconfig) { | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| const { compilerOptions, entryPoints } = tsconfig; | ||
|
|
||
| const params = { compilerOptions, debug, entryPoints, log }; | ||
|
|
||
| // TODO: define a unified `package.json#/skuba` schema and parser so we don't | ||
| // need all these messy lookups. | ||
| const tool = await getStringPropFromConsumerManifest('build'); | ||
|
|
||
| switch (tool) { | ||
| case 'esbuild': { | ||
| log.plain(chalk.yellow('esbuild')); | ||
| await run.esbuild(params, args); | ||
| break; | ||
| } | ||
|
|
||
| // TODO: flip the default case over to `esbuild` in skuba vNext. | ||
| case undefined: | ||
| case 'tsc': { | ||
| log.plain(chalk.blue('tsc')); | ||
| await run.tsc(params, args); | ||
| break; | ||
| } | ||
|
|
||
| default: { | ||
| log.err( | ||
| 'We don’t support the build tool specified in your', | ||
| log.bold('package.json'), | ||
| 'yet:', | ||
| ); | ||
| log.err(log.subtle(JSON.stringify({ skuba: { build: tool } }, null, 2))); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
| } | ||
| }; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these
entryPointsare not correct forbundle: true. Strictly speaking it should only output the rootlib/index.mjsunless moreexportsare defined.