@@ -6,10 +6,9 @@ import { fileURLToPath } from 'node:url';
6
6
import replace from '@rollup/plugin-replace' ;
7
7
import rollupSWC from '@rollup/plugin-swc' ;
8
8
import terser from '@rollup/plugin-terser' ;
9
- import ms from 'ms ' ;
9
+ import { dts } from 'rollup-plugin-dts ' ;
10
10
import * as insert from 'rollup-plugin-insert' ;
11
11
import ts from 'typescript' ;
12
- import { $ , chalk } from 'zx' ;
13
12
14
13
import inline from './inline.js' ;
15
14
@@ -79,61 +78,23 @@ export function tsconfig(updates) {
79
78
/**
80
79
* @param {PackageInfo } pkg
81
80
* @param {'dev' | 'prod' } env
82
- * @returns {RollupPlugin[] }
81
+ * @returns {RollupPlugin }
83
82
*/
84
83
export function typescript ( pkg , env ) {
85
84
if ( ! env ) {
86
85
throw new Error ( 'env is required' ) ;
87
86
}
88
87
89
- return [
90
- rollupSWC ( {
91
- swc : {
92
- jsc : {
93
- parser : {
94
- syntax : 'typescript' ,
95
- // decorators: true,
96
- } ,
97
- target : 'es2022' ,
98
- transform : {
99
- // legacyDecorator: true,
100
- } ,
88
+ return rollupSWC ( {
89
+ swc : {
90
+ jsc : {
91
+ parser : {
92
+ syntax : 'typescript' ,
101
93
} ,
102
- } ,
103
- } ) ,
104
- {
105
- name : 'Build Declarations' ,
106
- closeBundle : async function ( ) {
107
- const types = [ '@glimmer-workspace/env' ] ;
108
- if ( pkg . devDependencies [ '@types/node' ] ) {
109
- types . push ( 'node' ) ;
110
- }
111
-
112
- const start = performance . now ( ) ;
113
- await $ ( {
114
- verbose : true ,
115
- stdio : 'inherit' ,
116
- cwd : pkg . root ,
117
- } ) `pnpm tsc --skipLibCheck --declaration --declarationDir dist/${ env } --emitDeclarationOnly --module esnext --moduleResolution bundler ${
118
- pkg . exports
119
- } --types ${ types . join ( ',' ) } --target esnext --strict`;
120
- const duration = performance . now ( ) - start ;
121
- console . error (
122
- `${ chalk . green ( 'created' ) } ${ chalk . green . bold ( `dist/${ env } /index.d.ts` ) } ${ chalk . green (
123
- 'in'
124
- ) } ${ chalk . green . bold ( ms ( duration ) ) } `
125
- ) ;
94
+ target : 'es2022' ,
126
95
} ,
127
96
} ,
128
-
129
- // rollupTS({
130
- // compilerOptions: ts,
131
- // noForceEmit: true,
132
- // tsconfig: false,
133
- // // respectExternal: true,
134
- // // tsconfig: resolve(pkg.root, '../tsconfig.json'),
135
- // }),
136
- ] ;
97
+ } ) ;
137
98
}
138
99
139
100
/** @type {['is' | 'startsWith', string[], 'inline' | 'external'][] } */
@@ -380,58 +341,97 @@ export class Package {
380
341
* @returns {RollupOptions[] }
381
342
*/
382
343
rollupESM ( { env } ) {
383
- return this . #shared( 'esm' , env ) . map (
384
- ( options ) =>
385
- /** @satisfies {RollupOptions } */ ( {
386
- ...options ,
387
- external : this . #external,
388
- plugins : [
389
- inline ( ) ,
390
- nodePolyfills ( ) ,
391
- nodeResolve ( { extensions : [ '.js' , '.ts' ] } ) ,
392
- ...this . replacements ( env ) ,
393
- ...( env === 'prod'
394
- ? [
395
- terser ( {
396
- module : true ,
397
- // to debug the output, uncomment this so you can read the
398
- // identifiers, unchanged
399
- // mangle: false,
400
- compress : {
401
- passes : 3 ,
402
- keep_fargs : false ,
403
- keep_fnames : false ,
404
- // unsafe_arrows: true,
405
- // unsafe_comps: true,
406
- // unsafe_math: true,
407
- // unsafe_symbols: true,
408
- // unsafe_function: true,
409
- // unsafe_undefined: true,
410
- // keep_classnames: false,
411
- // toplevel: true,
412
- } ,
413
- } ) ,
414
- ]
415
- : [
416
- terser ( {
417
- module : true ,
418
- mangle : false ,
419
- compress : {
420
- passes : 3 ,
421
- keep_fargs : false ,
422
- keep_fnames : false ,
423
- } ,
424
- format : {
425
- comments : 'all' ,
426
- beautify : true ,
427
- } ,
428
- } ) ,
429
- ] ) ,
430
- postcss ( ) ,
431
- ...typescript ( this . #package, env ) ,
432
- ] ,
433
- } )
434
- ) ;
344
+ return [
345
+ ...this . #shared( 'esm' , env ) . map (
346
+ ( options ) =>
347
+ /** @satisfies {RollupOptions } */ ( {
348
+ ...options ,
349
+ external : this . #external,
350
+ plugins : [
351
+ inline ( ) ,
352
+ nodePolyfills ( ) ,
353
+ nodeResolve ( { extensions : [ '.js' , '.ts' ] } ) ,
354
+ ...this . replacements ( env ) ,
355
+ ...( env === 'prod'
356
+ ? [
357
+ terser ( {
358
+ module : true ,
359
+ // to debug the output, uncomment this so you can read the
360
+ // identifiers, unchanged
361
+ // mangle: false,
362
+ compress : {
363
+ passes : 3 ,
364
+ keep_fargs : false ,
365
+ keep_fnames : false ,
366
+ // unsafe_arrows: true,
367
+ // unsafe_comps: true,
368
+ // unsafe_math: true,
369
+ // unsafe_symbols: true,
370
+ // unsafe_function: true,
371
+ // unsafe_undefined: true,
372
+ // keep_classnames: false,
373
+ // toplevel: true,
374
+ } ,
375
+ } ) ,
376
+ ]
377
+ : [
378
+ terser ( {
379
+ module : true ,
380
+ mangle : false ,
381
+ compress : {
382
+ passes : 3 ,
383
+ keep_fargs : false ,
384
+ keep_fnames : false ,
385
+ } ,
386
+ format : {
387
+ comments : 'all' ,
388
+ beautify : true ,
389
+ } ,
390
+ } ) ,
391
+ ] ) ,
392
+ postcss ( ) ,
393
+ typescript ( this . #package, env ) ,
394
+ ] ,
395
+ } )
396
+ ) ,
397
+ ...( [ `@glimmer/vm-babel-plugins` ] . includes ( this . #package. name )
398
+ ? [ ]
399
+ : [
400
+ /**
401
+ * Why is this a different rollup pipeline?
402
+ * - other plugins interfere with the output (terser)
403
+ *
404
+ * Why dts instead of tsc directrly or rollupTS
405
+ * - rollup-plugin-typescript outputs compiled code, we have SWC for that (faster)
406
+ * - tsc does not rollup types
407
+ */
408
+ {
409
+ input : this . #package. exports ,
410
+ output : {
411
+ dir : `dist/${ env } ` ,
412
+ } ,
413
+ plugins : [
414
+ dts ( {
415
+ respectExternal : true ,
416
+ compilerOptions : {
417
+ skipLibCheck : true ,
418
+ declaration : true ,
419
+ declarationDir : `dist/${ env } ` ,
420
+ emitDeclarationOnly : true ,
421
+ moduleResolution : ts . ModuleResolutionKind . Bundler ,
422
+ module : ts . ModuleKind . ESNext ,
423
+ target : ts . ScriptTarget . ESNext ,
424
+ strict : true ,
425
+ types : [
426
+ '@glimmer-workspace/env' ,
427
+ ...( this . #package. devDependencies [ '@types/node' ] ? [ 'node' ] : [ ] ) ,
428
+ ] ,
429
+ } ,
430
+ } ) ,
431
+ ] ,
432
+ } ,
433
+ ] ) ,
434
+ ] ;
435
435
}
436
436
437
437
/**
0 commit comments