@carbon/cli 11.41.0 → 11.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/cli",
3
3
  "description": "Task automation for working with the Carbon Design System",
4
- "version": "11.41.0",
4
+ "version": "11.42.0",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "bin": {
@@ -34,9 +34,6 @@
34
34
  "@octokit/plugin-retry": "^3.0.7",
35
35
  "@octokit/plugin-throttling": "^4.0.0",
36
36
  "@octokit/rest": "^22.0.0",
37
- "@rollup/plugin-babel": "^6.0.0",
38
- "@rollup/plugin-commonjs": "^28.0.3",
39
- "@rollup/plugin-node-resolve": "^15.0.0",
40
37
  "chalk": "^5.4.1",
41
38
  "change-case-all": "^2.1.0",
42
39
  "child-process-promise": "^2.2.1",
@@ -52,10 +49,10 @@
52
49
  "progress-estimator": "^0.3.0",
53
50
  "remark": "^15.0.1",
54
51
  "replace-in-file": "^8.3.0",
55
- "rollup": "^4.41.1",
56
52
  "sass": "^1.77.7",
57
- "typescript-config-carbon": "^0.9.0",
53
+ "tsdown": "^0.20.3",
54
+ "typescript": "^5.7.3",
58
55
  "yargs": "^17.7.2"
59
56
  },
60
- "gitHead": "4f48ac426be7302a57460b1c81d74dd5d6071ad6"
57
+ "gitHead": "aeaaa31889990fc76c7e0e8a29ec0bf96ce33f82"
61
58
  }
@@ -5,94 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { babel } from '@rollup/plugin-babel';
9
- import commonjs from '@rollup/plugin-commonjs';
10
- import { nodeResolve } from '@rollup/plugin-node-resolve';
11
- import fs from 'fs-extra';
12
- import path from 'path';
13
- import { rollup } from 'rollup';
14
- import {
15
- formatGlobals,
16
- findPackageFolder,
17
- formatDependenciesIntoGlobals,
18
- } from './utils.js';
8
+ import bundleWithTsdown from './tsdown.js';
19
9
 
20
- export default async function bundle(entrypoint, options) {
21
- const globals = options.globals ? formatGlobals(options.globals) : {};
22
- const { name } = options;
23
- const packageFolder = await findPackageFolder(entrypoint);
24
-
25
- const outputFolders = [
26
- {
27
- format: 'esm',
28
- directory: path.join(packageFolder, 'es'),
29
- },
30
- {
31
- format: 'cjs',
32
- directory: path.join(packageFolder, 'lib'),
33
- },
34
- {
35
- format: 'umd',
36
- directory: path.join(packageFolder, 'umd'),
37
- },
38
- ];
39
-
40
- await Promise.all(outputFolders.map(({ directory }) => fs.remove(directory)));
41
-
42
- const jsEntryPoints = outputFolders.map(({ directory, format }) => ({
43
- file: path.join(directory, 'index.js'),
44
- format,
45
- }));
46
-
47
- const packageJsonPath = path.join(packageFolder, 'package.json');
48
- const packageJson = await fs.readJson(packageJsonPath);
49
- const { dependencies = {} } = packageJson;
50
-
51
- const bundle = await rollup({
52
- input: entrypoint,
53
- external: Object.keys(dependencies),
54
- plugins: [
55
- babel({
56
- exclude: 'node_modules/**',
57
- babelrc: false,
58
- presets: [
59
- [
60
- '@babel/preset-env',
61
- {
62
- modules: false,
63
- targets: {
64
- browsers: ['last 1 version', 'ie >= 11', 'Firefox ESR'],
65
- },
66
- },
67
- ],
68
- ],
69
- babelHelpers: 'bundled',
70
- }),
71
- nodeResolve(),
72
- commonjs({
73
- include: [/node_modules/],
74
- extensions: ['.js'],
75
- }),
76
- ],
77
- });
78
-
79
- await Promise.all(
80
- jsEntryPoints.map(({ format, file }) => {
81
- const outputOptions = {
82
- format,
83
- file,
84
- exports: 'auto',
85
- };
86
-
87
- if (format === 'umd') {
88
- outputOptions.name = name;
89
- outputOptions.globals = {
90
- ...formatDependenciesIntoGlobals(dependencies),
91
- ...globals,
92
- };
93
- }
94
-
95
- return bundle.write(outputOptions);
96
- })
97
- );
98
- }
10
+ export default bundleWithTsdown;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Copyright IBM Corp. 2019, 2025
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import fs from 'fs-extra';
9
+ import path from 'path';
10
+ import { build } from 'tsdown';
11
+ import ts from 'typescript';
12
+ import {
13
+ findPackageFolder,
14
+ formatDependenciesIntoGlobals,
15
+ formatGlobals,
16
+ } from './utils.js';
17
+
18
+ export default async function bundle(entrypoint, options) {
19
+ const globals = options.globals ? formatGlobals(options.globals) : {};
20
+ const { name, dts } = options;
21
+ const packageFolder = await findPackageFolder(entrypoint);
22
+
23
+ const outputFolders = [
24
+ {
25
+ format: 'esm',
26
+ directory: path.join(packageFolder, 'es'),
27
+ },
28
+ {
29
+ format: 'cjs',
30
+ directory: path.join(packageFolder, 'lib'),
31
+ },
32
+ {
33
+ format: 'umd',
34
+ directory: path.join(packageFolder, 'umd'),
35
+ },
36
+ ];
37
+
38
+ await Promise.all(outputFolders.map(({ directory }) => fs.remove(directory)));
39
+
40
+ const packageJsonPath = path.join(packageFolder, 'package.json');
41
+ const packageJson = await fs.readJson(packageJsonPath);
42
+ const { dependencies = {} } = packageJson;
43
+ const umdGlobals = {
44
+ ...formatDependenciesIntoGlobals(dependencies),
45
+ ...globals,
46
+ };
47
+
48
+ for (const { format, directory } of outputFolders) {
49
+ await build({
50
+ clean: false,
51
+ // Emit declarations in a separate pass so we can mirror the same `.d.ts`
52
+ // tree to `es`, `lib`, and `umd`.
53
+ dts: false,
54
+ entry: [entrypoint],
55
+ external: Object.keys(dependencies),
56
+ failOnWarn: false,
57
+ format,
58
+ globalName: format === 'umd' ? name : undefined,
59
+ outDir: directory,
60
+ outputOptions(outputOptions) {
61
+ const options = {
62
+ ...outputOptions,
63
+ entryFileNames: 'index.js',
64
+ };
65
+
66
+ if (format === 'umd') {
67
+ return {
68
+ ...options,
69
+ globals: umdGlobals,
70
+ name,
71
+ };
72
+ }
73
+
74
+ return options;
75
+ },
76
+ platform: 'browser',
77
+ report: false,
78
+ target: 'es2022',
79
+ });
80
+ }
81
+
82
+ if (dts) {
83
+ await emitDeclarations(packageFolder);
84
+ await copyDeclarations(
85
+ path.join(packageFolder, 'es'),
86
+ path.join(packageFolder, 'lib')
87
+ );
88
+ await copyDeclarations(
89
+ path.join(packageFolder, 'es'),
90
+ path.join(packageFolder, 'umd')
91
+ );
92
+ }
93
+ }
94
+
95
+ async function copyDeclarations(fromDir, toDir) {
96
+ const entries = await fs.readdir(fromDir, { withFileTypes: true });
97
+
98
+ for (const entry of entries) {
99
+ const fromPath = path.join(fromDir, entry.name);
100
+ const toPath = path.join(toDir, entry.name);
101
+
102
+ if (entry.isDirectory()) {
103
+ await fs.ensureDir(toPath);
104
+ await copyDeclarations(fromPath, toPath);
105
+ continue;
106
+ }
107
+
108
+ if (entry.name.endsWith('.d.ts')) {
109
+ await fs.copy(fromPath, toPath);
110
+ }
111
+ }
112
+ }
113
+
114
+ async function emitDeclarations(packageFolder) {
115
+ const tsconfigPath = ts.findConfigFile(
116
+ packageFolder,
117
+ ts.sys.fileExists,
118
+ 'tsconfig.json'
119
+ );
120
+
121
+ if (!tsconfigPath) {
122
+ throw new Error(`Unable to find tsconfig.json in ${packageFolder}`);
123
+ }
124
+
125
+ const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
126
+
127
+ if (configFile.error) {
128
+ throw new Error(formatDiagnostics([configFile.error]));
129
+ }
130
+
131
+ const parsed = ts.parseJsonConfigFileContent(
132
+ configFile.config,
133
+ ts.sys,
134
+ path.dirname(tsconfigPath),
135
+ {
136
+ declaration: true,
137
+ emitDeclarationOnly: true,
138
+ noEmit: false,
139
+ outDir: path.join(packageFolder, 'es'),
140
+ skipLibCheck: true,
141
+ types: [],
142
+ },
143
+ tsconfigPath
144
+ );
145
+
146
+ const testsDirectoryPattern = `${path.sep}__tests__${path.sep}`;
147
+ const rootNames = parsed.fileNames.filter((filename) => {
148
+ return !filename.includes(testsDirectoryPattern);
149
+ });
150
+
151
+ const program = ts.createProgram({
152
+ rootNames,
153
+ options: parsed.options,
154
+ });
155
+ const emitResult = program.emit();
156
+ const diagnostics = ts
157
+ .getPreEmitDiagnostics(program)
158
+ .concat(emitResult.diagnostics || []);
159
+
160
+ if (diagnostics.length > 0) {
161
+ throw new Error(formatDiagnostics(diagnostics));
162
+ }
163
+ }
164
+
165
+ function formatDiagnostics(diagnostics) {
166
+ return ts.formatDiagnosticsWithColorAndContext(diagnostics, {
167
+ getCanonicalFileName: (filename) => filename,
168
+ getCurrentDirectory: () => process.cwd(),
169
+ getNewLine: () => ts.sys.newLine,
170
+ });
171
+ }
@@ -5,110 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { babel } from '@rollup/plugin-babel';
9
- import commonjs from '@rollup/plugin-commonjs';
10
- import { nodeResolve } from '@rollup/plugin-node-resolve';
11
- import typescript from '@rollup/plugin-typescript';
12
- import fs from 'fs-extra';
13
- import path from 'path';
14
- import { rollup } from 'rollup';
15
- import { loadBaseTsCompilerOpts } from 'typescript-config-carbon';
16
- import {
17
- formatGlobals,
18
- findPackageFolder,
19
- formatDependenciesIntoGlobals,
20
- } from './utils.js';
8
+ import bundleWithTsdown from './tsdown.js';
21
9
 
22
- export default async function bundle(entrypoint, options) {
23
- const globals = options.globals ? formatGlobals(options.globals) : {};
24
- const { name } = options;
25
- const packageFolder = await findPackageFolder(entrypoint);
26
-
27
- const outputFolders = [
28
- {
29
- format: 'esm',
30
- directory: path.join(packageFolder, 'es'),
31
- },
32
- {
33
- format: 'cjs',
34
- directory: path.join(packageFolder, 'lib'),
35
- },
36
- {
37
- format: 'umd',
38
- directory: path.join(packageFolder, 'umd'),
39
- },
40
- ];
41
-
42
- await Promise.all(outputFolders.map(({ directory }) => fs.remove(directory)));
43
-
44
- const jsEntryPoints = outputFolders.map(({ directory, format }) => ({
45
- outputDir: directory,
46
- file: path.join(directory, 'index.js'),
47
- format,
48
- }));
49
-
50
- const packageJsonPath = path.join(packageFolder, 'package.json');
51
- const packageJson = await fs.readJson(packageJsonPath);
52
- const { dependencies = {} } = packageJson;
53
-
54
- const baseTsCompilerOpts = loadBaseTsCompilerOpts();
55
-
56
- await Promise.all(
57
- jsEntryPoints.map(async ({ outputDir, file, format }) => {
58
- const bundle = await rollup({
59
- input: entrypoint,
60
- external: Object.keys(dependencies),
61
- plugins: [
62
- typescript({
63
- noEmitOnError: true,
64
- noForceEmit: true,
65
- outputToFilesystem: false,
66
- compilerOptions: {
67
- ...baseTsCompilerOpts,
68
- rootDir: 'src',
69
- outDir: outputDir,
70
- },
71
- }),
72
- babel({
73
- exclude: 'node_modules/**',
74
- babelrc: false,
75
- presets: [
76
- [
77
- '@babel/preset-env',
78
- {
79
- modules: false,
80
- targets: {
81
- browsers: ['last 1 version', 'ie >= 11', 'Firefox ESR'],
82
- },
83
- },
84
- ],
85
- '@babel/preset-typescript',
86
- ],
87
- babelHelpers: 'bundled',
88
- extensions: ['.ts', '.tsx', '.js', '.jsx'],
89
- }),
90
- nodeResolve(),
91
- commonjs({
92
- include: [/node_modules/],
93
- extensions: ['.js'],
94
- }),
95
- ],
96
- });
97
- const outputOptions = {
98
- exports: 'auto',
99
- file,
100
- format,
101
- };
102
-
103
- if (format === 'umd') {
104
- outputOptions.name = name;
105
- outputOptions.globals = {
106
- ...formatDependenciesIntoGlobals(dependencies),
107
- ...globals,
108
- };
109
- }
110
-
111
- return bundle.write(outputOptions);
112
- })
113
- );
114
- }
10
+ export default bundleWithTsdown;
@@ -11,7 +11,7 @@ import bundlers from './bundle/bundlers.js';
11
11
 
12
12
  const logger = createLogger('bundle');
13
13
 
14
- async function bundle({ entrypoint, name, globals }) {
14
+ async function bundle({ entrypoint, name, globals, dts }) {
15
15
  logger.start('bundle');
16
16
 
17
17
  const cwd = process.cwd();
@@ -29,6 +29,7 @@ async function bundle({ entrypoint, name, globals }) {
29
29
  await bundle(path.join(cwd, entrypoint), {
30
30
  name,
31
31
  globals,
32
+ dts,
32
33
  });
33
34
  } catch (error) {
34
35
  logger.info(`Unexpected error occurred while bundling ${entrypoint}:`);
@@ -56,6 +57,11 @@ export const builder = (yargs) => {
56
57
  describe: 'global module names',
57
58
  type: 'string',
58
59
  },
60
+ dts: {
61
+ describe: 'emit TypeScript declaration files',
62
+ type: 'boolean',
63
+ default: false,
64
+ },
59
65
  });
60
66
  };
61
67
  export const command = 'bundle <entrypoint>';
@@ -20,7 +20,6 @@ async function check(args, env) {
20
20
  `yarn carbon-cli check --ignore '**/@(node_modules|examples|components|react|fixtures|compat)/**' 'packages/**/*.scss'`,
21
21
  `cross-env BABEL_ENV=test yarn test --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
22
22
  `cross-env BABEL_ENV=test yarn test:e2e --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
23
- `cross-env PERCY_TOKEN=dd3392142006a6483c8f524697f39f052755fa9dc087ff4437cac3d64227abdd yarn run percy exec -- yarn workspace @carbon/react test:e2e`,
24
23
  ];
25
24
 
26
25
  try {