Skip to content

Commit c3c2c73

Browse files
Entry Points pre-work [LG-5028] (#2805)
* revert to node10 for some packages * mv testing dir * add /testing entry point * adds postinstall script to code to fix hljs * update base tsconfig * fix code ts * fix code ts * updates tools/build * Moves `.less` bundling to palette rollup config * Update pnpm-lock.yaml * Update pnpm-lock.yaml * Update linkPackageTo.spec.ts * Update Select.spec.tsx * Create palette-bundle-less.md
1 parent 6df1764 commit c3c2c73

30 files changed

+342
-154
lines changed

.changeset/build-rollup-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@lg-tools/build': minor
3+
---
4+
5+
- Only adds output `globals` for UMD builds
6+
- Splits `/testing` entry point if `src/testing/index.ts` file exists

.changeset/code-postinstall-hljs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@leafygreen-ui/code': minor
3+
---
4+
5+
Adds postinstall script to ensure dependency types are resolved correctly

.changeset/palette-bundle-less.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@leafygreen-ui/palette': patch
3+
---
4+
5+
Creates local Rollup config to bundle `.less` files

charts/core/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@lg-tools/build/config/package.tsconfig.json",
33
"compilerOptions": {
4+
"moduleResolution": "node",
45
"paths": {
56
"@leafygreen-ui/icon/dist/*": [
67
"../../packages/icon/src/generated/*"

chat/lg-markdown/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "@lg-tools/build/config/package.tsconfig.json",
33
"compilerOptions": {
4+
"moduleResolution": "node",
5+
46
"paths": {
57
"@leafygreen-ui/icon/dist/*": [
68
"../../packages/icon/src/generated/*"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"chromatic": "npx chromatic",
2323
"clean": "npm-run-all --parallel clean:*",
2424
"clean:builds": "pnpm recursive exec -- rm -rf ./{dist,tsconfig.tsbuildinfo,stories.js}",
25+
"clean:ts": "pnpm recursive exec -- rm -rf ./{dist/**/*.d.ts.,tsconfig.tsbuildinfo}",
2526
"clean:cache": "pnpm recursive exec -- rm -rf ./.turbo; rm -rf .turbo/cache",
2627
"clean:modules": "pnpm recursive exec -- rm -rf node_modules; rm -rf node_modules",
2728
"fix": "lg lint --fix",

packages/code/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"scripts": {
1010
"build": "lg build-package",
1111
"tsc": "lg build-ts",
12-
"docs": "lg build-tsdoc"
12+
"docs": "lg build-tsdoc",
13+
"postinstall": "npx ts-node scripts/postinstall.ts"
1314
},
1415
"keywords": [],
1516
"license": "Apache-2.0",
@@ -40,7 +41,6 @@
4041
"lodash": "^4.17.21",
4142
"polished": "^4.2.2"
4243
},
43-
"devDependencies": {},
4444
"peerDependencies": {
4545
"@leafygreen-ui/leafygreen-provider": "workspace:^"
4646
},

packages/code/scripts/postinstall.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* eslint-disable no-console */
2+
import packageConfig from '@lg-tools/build/config/package.tsconfig.json';
3+
import fs from 'fs';
4+
import path from 'path';
5+
6+
const highlightJsPath = path.resolve(
7+
__dirname,
8+
'..',
9+
'node_modules',
10+
'highlight.js',
11+
);
12+
13+
const tsConfigPath = path.join(highlightJsPath, 'tsconfig.json');
14+
15+
/**
16+
* This script adds a tsconfig.json file to the highlight.js module in node_modules,
17+
* to ensure TypeScript can properly resolve types when importing highlight.js
18+
*
19+
* Hopefully this will be removed in the future.
20+
*/
21+
async function main() {
22+
try {
23+
if (fs.existsSync(highlightJsPath)) {
24+
if (fs.existsSync(tsConfigPath)) {
25+
// If the tsconfig.json file already exists, skip creating it
26+
return;
27+
}
28+
29+
console.log('📦 Adding tsconfig.json to highlight.js module...');
30+
31+
// Define the tsconfig.json content
32+
const tsconfig = {
33+
...packageConfig,
34+
compilerOptions: {
35+
...packageConfig.compilerOptions,
36+
baseUrl: './types',
37+
},
38+
};
39+
40+
// Write the tsconfig.json file to the highlight.js directory
41+
fs.writeFileSync(tsConfigPath, JSON.stringify(tsconfig, null, 2));
42+
43+
console.log(`✅ Successfully wrote file ${tsConfigPath}`);
44+
} else {
45+
console.log(
46+
'⚠️ highlight.js module not found in node_modules. Skipping tsconfig.json creation.',
47+
);
48+
}
49+
} catch (error) {
50+
console.error(
51+
'❌ Error adding tsconfig.json to highlight.js module:',
52+
error,
53+
);
54+
process.exit(1);
55+
}
56+
}
57+
58+
main().catch(error => {
59+
console.error('❌ Unhandled error:', error);
60+
process.exit(1);
61+
});

packages/code/scripts/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@lg-tools/build/config/script.tsconfig.json",
3+
"compilerOptions": {
4+
"noUnusedLocals": false,
5+
"strict": true,
6+
"baseUrl": ".",
7+
}
8+
}

packages/code/src/CopyButton/CopyButton.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ function CopyButton({ onCopy, contents, className, ...rest }: CopyProps) {
6262

6363
const clipboard = new ClipboardJS(buttonRef.current, {
6464
text: () => contents,
65-
// @ts-expect-error TODO: types
66-
container: portalContainer,
65+
container: portalContainer ?? undefined,
6766
});
6867

6968
if (copied) {

packages/code/src/utils/getTestUtils/getTestUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getByLgId, queryBySelector } from '@lg-tools/test-harnesses';
22

33
import { getTestUtils as getButtonTestUtils } from '@leafygreen-ui/button';
4-
import { getTestUtils as getSelectTestUtils } from '@leafygreen-ui/select';
4+
import { getTestUtils as getSelectTestUtils } from '@leafygreen-ui/select/testing';
55

66
import { DEFAULT_LGID_ROOT, getLgIds } from '../getLgIds';
77

packages/code/src/utils/getTestUtils/getTestUtils.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GetTestUtilsReturnType as GetButtonTestUtilsReturnType } from '@leafygreen-ui/button';
2-
import { GetTestUtilsReturnType as GetSelectTestUtilsReturnType } from '@leafygreen-ui/select';
2+
import type { GetTestUtilsReturnType as GetSelectTestUtilsReturnType } from '@leafygreen-ui/select/testing';
33

44
export interface TestUtilsReturnType {
55
/**

packages/code/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@lg-tools/build/config/package.tsconfig.json",
33
"compilerOptions": {
4+
"moduleResolution": "node",
45
"paths": {
56
"@leafygreen-ui/icon/dist/*": [
67
"../icon/src/generated/*"

packages/palette/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
"publishConfig": {
1616
"access": "public"
1717
},
18+
"dependencies": {},
1819
"devDependencies": {
1920
"@leafygreen-ui/emotion": "workspace:^",
2021
"@leafygreen-ui/lib": "workspace:^",
22+
"@rollup/plugin-url": "8.0.2",
2123
"polished": "^4.2.2"
2224
},
2325
"gitHead": "dd71a2d404218ccec2e657df9c0263dc1c15b9e0",
@@ -28,6 +30,5 @@
2830
},
2931
"bugs": {
3032
"url": "https://jira.mongodb.org/projects/PD/summary"
31-
},
32-
"dependencies": {}
33+
}
3334
}

packages/palette/rollup.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import urlPlugin from '@rollup/plugin-url';
2+
import {
3+
esmConfig,
4+
umdConfig,
5+
storiesConfig,
6+
} from '@lg-tools/build/config/rollup.config.mjs';
7+
8+
export default [
9+
{
10+
...esmConfig,
11+
plugins: [
12+
...esmConfig.plugins,
13+
urlPlugin({
14+
limit: 0,
15+
include: ['**/*.less'],
16+
fileName: '[name][extname]',
17+
}),
18+
],
19+
},
20+
{
21+
...umdConfig,
22+
plugins: [
23+
...esmConfig.plugins,
24+
urlPlugin({
25+
limit: 0,
26+
include: ['**/*.less'],
27+
fileName: '[name][extname]',
28+
}),
29+
],
30+
},
31+
storiesConfig,
32+
];

packages/select/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
"module": "./dist/esm/index.js",
77
"types": "./dist/types/index.d.ts",
88
"typesVersions": {},
9+
"exports": {
10+
".": {
11+
"import": "./dist/esm/index.js",
12+
"require": "./dist/index.js",
13+
"types": "./dist/index.d.ts"
14+
},
15+
"./testing": {
16+
"import": "./dist/esm/testing/index.js",
17+
"require": "./dist/testing/index.js",
18+
"types": "./dist/testing/index.d.ts"
19+
}
20+
},
921
"scripts": {
1022
"build": "lg build-package",
1123
"tsc": "lg build-ts",

packages/select/rollup.config.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
esmConfig,
3+
umdConfig,
4+
storiesConfig,
5+
} from '@lg-tools/build/config/rollup.config.mjs';
6+
7+
const esmTestUtilsConfig = {
8+
...esmConfig,
9+
input: 'src/testing/index.ts',
10+
output: {
11+
...esmConfig.output,
12+
dir: 'dist/esm/testing',
13+
},
14+
};
15+
const umdTestUtilsConfig = {
16+
...umdConfig,
17+
input: 'src/testing/index.ts',
18+
output: {
19+
...umdConfig.output,
20+
dir: 'dist/testing',
21+
},
22+
};
23+
24+
export default [
25+
esmConfig,
26+
umdConfig,
27+
esmTestUtilsConfig,
28+
umdTestUtilsConfig,
29+
storiesConfig,
30+
];

packages/select/src/Select/Select.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import { keyMap } from '@leafygreen-ui/lib';
1616
import { RenderMode } from '@leafygreen-ui/popover';
1717
import { Context, jest as Jest } from '@leafygreen-ui/testing-lib';
1818

19-
import { getTestUtils } from '../utils/getTestUtils/getTestUtils';
20-
import { TestUtilsReturnType } from '../utils/getTestUtils/getTestUtils.types';
19+
import { getTestUtils, type TestUtilsReturnType } from '../testing';
2120
import { Option, OptionGroup, Select } from '..';
2221

2322
import { SelectProps, State } from './Select.types';

packages/select/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ export {
1212
Size,
1313
State,
1414
} from './Select';
15-
export { getTestUtils, type GetTestUtilsReturnType } from './utils';

packages/select/src/testing/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { getTestUtils } from './utils/getTestUtils';
2+
export type { GetTestUtilsReturnType } from './utils/getTestUtils.types';

packages/select/src/utils/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/build/config/package.tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"strictNullChecks": true,
1919
"pretty": true,
2020
"skipLibCheck": true,
21+
"lib": ["DOM", "DOM.Iterable", "ES2020"],
2122
"baseUrl": "${configDir}",
2223
"rootDir": "${configDir}/src",
2324
"outDir": "${configDir}/dist",

0 commit comments

Comments
 (0)