Skip to content

Commit e0a636d

Browse files
authored
fix: utilities exports (#927)
* fix: name window check and package compatibility * fix: utilities package exports * fix: rollup resolution
1 parent dc85d99 commit e0a636d

File tree

7 files changed

+124
-9
lines changed

7 files changed

+124
-9
lines changed

packages/react/tasks/build.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ const packageJSON = JSON.parse(
2929
readFileSync(path.resolve(__dirname, '../package.json'))
3030
);
3131

32+
// Read component-level package.json if it exists
33+
let componentPackageJSON = {};
34+
try {
35+
componentPackageJSON = JSON.parse(
36+
readFileSync(path.resolve(process.cwd(), 'package.json'))
37+
);
38+
} catch (e) {
39+
// No component package.json, use empty object
40+
}
41+
3242
/**
3343
* build function
3444
*/
@@ -131,15 +141,21 @@ function getTsCompilerOptions() {
131141
* @returns
132142
*/
133143
function getRollupConfig(input, rootDir, outDir) {
144+
// Merge dependencies from both main package.json and component package.json
145+
const allDependencies = {
146+
...packageJSON.peerDependencies,
147+
...packageJSON.dependencies,
148+
...packageJSON.devDependencies,
149+
...componentPackageJSON.peerDependencies,
150+
...componentPackageJSON.dependencies,
151+
...componentPackageJSON.devDependencies,
152+
};
153+
134154
return {
135155
input,
136156
// Mark dependencies listed in `package.json` as external so that they are
137157
// not included in the output bundle.
138-
external: [
139-
...Object.keys(packageJSON.peerDependencies),
140-
...Object.keys(packageJSON.dependencies),
141-
...Object.keys(packageJSON.devDependencies),
142-
].map((name) => {
158+
external: Object.keys(allDependencies).map((name) => {
143159
// Transform the name of each dependency into a regex so that imports from
144160
// nested paths are correctly marked as external.
145161
//

packages/utilities/package.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,31 @@
1313
"url": "https://github.com/carbon-design-system/carbon-labs",
1414
"directory": "packages/utilities"
1515
},
16+
"main": "./es/index.js",
17+
"module": "./es/index.js",
18+
"types": "./es/index.d.ts",
19+
"sideEffects": false,
1620
"exports": {
1721
".": {
18-
"default": "./src/index.js"
22+
"types": "./es/index.d.ts",
23+
"import": "./es/index.js",
24+
"default": "./es/index.js"
1925
},
20-
"./es/": "./es/"
26+
"./es/*": {
27+
"types": "./es/*.d.ts",
28+
"import": "./es/*",
29+
"default": "./es/*"
30+
}
2131
},
2232
"scripts": {
23-
"build": "yarn clean && babel src --quiet -d es",
33+
"build": "bash scripts/build.sh",
2434
"clean": "rimraf es"
2535
},
2636
"files": [
2737
"es/**/*.js",
28-
"es/index.js"
38+
"es/**/*.d.ts",
39+
"es/index.js",
40+
"es/index.d.ts"
2941
],
3042
"dependencies": {
3143
"react": "^18.3.1",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Clean previous build
4+
yarn clean
5+
6+
# Transpile JavaScript with Babel
7+
babel src --quiet -d es
8+
9+
# Copy TypeScript declaration files
10+
find src -name "*.d.ts" -type f | while read file; do
11+
dest="es/${file#src/}"
12+
mkdir -p "$(dirname "$dest")"
13+
cp "$file" "$dest"
14+
done
15+
16+
# Made with Bob

packages/utilities/src/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
*
4+
* Copyright IBM Corp. 2024
5+
*
6+
* This source code is licensed under the Apache-2.0 license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
export * from './settings/index.js';
11+
export * from './usePrefix.js';
12+
13+
// Made with Bob
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license
3+
*
4+
* Copyright IBM Corp. 2024
5+
*
6+
* This source code is licensed under the Apache-2.0 license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
export { default as settings } from './settings.js';
11+
12+
// Made with Bob
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
*
4+
* Copyright IBM Corp. 2024
5+
*
6+
* This source code is licensed under the Apache-2.0 license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
interface Settings {
11+
/**
12+
* Stable prefix for Carbon Labs components
13+
* @default 'clabs'
14+
*/
15+
stablePrefix: string;
16+
17+
/**
18+
* Core Carbon prefix
19+
* @default 'cds'
20+
*/
21+
prefix: string;
22+
}
23+
24+
declare const settings: Settings;
25+
26+
export default settings;
27+
28+
// Made with Bob
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright IBM Corp. 2024
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 React from 'react';
9+
10+
export const PrefixContext: React.Context<string>;
11+
12+
/**
13+
* Sets the prefix context
14+
* @returns context value
15+
*/
16+
export function usePrefix(): string;
17+
18+
// Made with Bob

0 commit comments

Comments
 (0)