Skip to content

Commit b295fc6

Browse files
Merge pull request #1701 from glimmerjs/rollup-types
Rollup the types (solves missing types from unpublished packages)
2 parents a306d62 + 7a5e6c7 commit b295fc6

File tree

6 files changed

+138
-133
lines changed

6 files changed

+138
-133
lines changed

.meta-updater/main.mjs

+37-17
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,45 @@ export default () =>
7878

7979
update(actual, 'files', ['dist']);
8080

81-
update(publishConfig, 'exports', {
82-
'.': {
83-
development: {
84-
types: './dist/dev/index.d.ts',
85-
default: './dist/dev/index.js',
81+
if (pkg.name === '@glimmer/vm-babel-plugins') {
82+
update(publishConfig, 'exports', {
83+
'.': {
84+
development: {
85+
default: './dist/dev/index.js',
86+
},
87+
...(pkg['repo-meta']?.supportcjs
88+
? {
89+
require: {
90+
default: './dist/dev/index.cjs',
91+
},
92+
}
93+
: {}),
94+
default: {
95+
default: './dist/prod/index.js',
96+
},
8697
},
87-
...(pkg['repo-meta']?.supportcjs
88-
? {
89-
require: {
90-
default: './dist/dev/index.cjs',
91-
},
92-
}
93-
: {}),
94-
default: {
95-
types: './dist/prod/index.d.ts',
96-
default: './dist/prod/index.js',
98+
});
99+
} else {
100+
update(publishConfig, 'exports', {
101+
'.': {
102+
development: {
103+
types: './dist/dev/index.d.ts',
104+
default: './dist/dev/index.js',
105+
},
106+
...(pkg['repo-meta']?.supportcjs
107+
? {
108+
require: {
109+
default: './dist/dev/index.cjs',
110+
},
111+
}
112+
: {}),
113+
default: {
114+
types: './dist/prod/index.d.ts',
115+
default: './dist/prod/index.js',
116+
},
97117
},
98-
},
99-
});
118+
});
119+
}
100120
} else {
101121
delete publishConfig['exports'];
102122
delete scripts['prepack'];

packages/@glimmer-workspace/build/lib/config.js

+100-100
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { fileURLToPath } from 'node:url';
66
import replace from '@rollup/plugin-replace';
77
import rollupSWC from '@rollup/plugin-swc';
88
import terser from '@rollup/plugin-terser';
9-
import ms from 'ms';
9+
import { dts } from 'rollup-plugin-dts';
1010
import * as insert from 'rollup-plugin-insert';
1111
import ts from 'typescript';
12-
import { $, chalk } from 'zx';
1312

1413
import inline from './inline.js';
1514

@@ -79,61 +78,23 @@ export function tsconfig(updates) {
7978
/**
8079
* @param {PackageInfo} pkg
8180
* @param {'dev' | 'prod'} env
82-
* @returns {RollupPlugin[]}
81+
* @returns {RollupPlugin}
8382
*/
8483
export function typescript(pkg, env) {
8584
if (!env) {
8685
throw new Error('env is required');
8786
}
8887

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',
10193
},
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',
12695
},
12796
},
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+
});
13798
}
13899

139100
/** @type {['is' | 'startsWith', string[], 'inline' | 'external'][]} */
@@ -380,58 +341,97 @@ export class Package {
380341
* @returns {RollupOptions[]}
381342
*/
382343
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+
];
435435
}
436436

437437
/**

packages/@glimmer-workspace/build/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"@rollup/plugin-swc": "^0.4.0",
2424
"@rollup/plugin-terser": "^0.4.4",
2525
"@rollup/plugin-typescript": "^12.1.1",
26-
"@types/ms": "^2.1.0",
2726
"magic-string": "^0.30.0",
28-
"ms": "^2.1.3",
2927
"postcss": "^8.4.31",
3028
"rollup": "^4.31.0-0",
3129
"rollup-plugin-dts": "^6.1.1",

packages/@glimmer/vm-babel-plugins/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
"exports": {
1818
".": {
1919
"development": {
20-
"types": "./dist/dev/index.d.ts",
2120
"default": "./dist/dev/index.js"
2221
},
2322
"default": {
24-
"types": "./dist/prod/index.d.ts",
2523
"default": "./dist/prod/index.js"
2624
}
2725
}

pnpm-lock.yaml

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

repo-metadata/metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
{
168168
"root": "packages/@glimmer/compiler",
169169
"name": "@glimmer/compiler",
170-
"version": "0.94.3",
170+
"version": "0.94.4",
171171
"type": "module",
172172
"private": false,
173173
"repo-meta": {

0 commit comments

Comments
 (0)