Skip to content

Commit f2dbd9e

Browse files
committed
build: use TSGo (TS 7.0 dev) to speed up building types
Also simplify and put timers into the bootstrap script
1 parent ab0536f commit f2dbd9e

7 files changed

Lines changed: 89 additions & 91 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"packages/*"
1515
],
1616
"scripts": {
17-
"build:themes": "ui-scripts build-themes",
1817
"prestart": "pnpm run bootstrap",
1918
"start": "pnpm --filter docs-app start",
2019
"start:watch": "pnpm --filter docs-app start:watch",
@@ -30,6 +29,7 @@
3029
"build": "pnpm -r --stream build",
3130
"build:watch": "pnpm -r --stream build:watch",
3231
"build:docs": "pnpm --filter docs-app bundle",
32+
"build:themes": "ui-scripts build-themes",
3333
"build:tokens": "ui-scripts generate-all-tokens",
3434
"build:types": "tsc -b tsconfig.references.json",
3535
"build:ts": "pnpm --filter @instructure/ui-icons prepare-build && pnpm run build:types",

packages/__docs__/globals.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ import { LoremIpsum } from 'lorem-ipsum'
3636
import moment from 'moment'
3737
// @ts-expect-error no type declarations for moment locales side-effect import
3838
import 'moment/min/locales'
39-
4039
import { mirrorHorizontalPlacement } from '@instructure/ui-position'
41-
4240
import { getComponentsForVersion } from './versioned-components'
4341
import { dark, light } from '@instructure/ui-themes'
4442
import { debounce } from '@instructure/debounce'

packages/ui-table/src/Table/__tests__/Table.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('<Table />', async () => {
209209
<Table.Body>
210210
test
211211
<span>test</span>
212-
{/* @ts-ignore error is normal here */}
212+
{/* @ts-expect-error error is normal here */}
213213
<Table.Row>
214214
test
215215
<span>test</span>

pnpm-lock.yaml

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

regression-test/package-lock.json

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

scripts/bootstrap.js

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,71 +23,75 @@
2323
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
* SOFTWARE.
2525
*/
26-
const { execSync, fork } = require('child_process')
26+
const { execSync } = require('child_process')
2727
const path = require('path')
2828

2929
const opts = { stdio: 'inherit' }
30-
function buildProject() {
31-
console.info('Fetching design tokens...')
32-
try {
33-
execSync(
34-
'pnpm --filter @instructure/ui-scripts update @instructure/instructure-design-tokens',
35-
opts
36-
)
37-
} catch (error) {
38-
console.error(
39-
"'pnpm --filter @instructure/ui-scripts update @instructure/instructure-design-tokens' failed",
40-
error
41-
)
42-
process.exit(1)
43-
}
4430

45-
console.info('Building themes...')
46-
try {
47-
execSync('pnpm run build:themes', opts)
48-
} catch (error) {
49-
console.error("'pnpm run build:themes' failed", error)
50-
process.exit(1)
51-
}
31+
function format(ms) {
32+
return `${(ms / 1000).toFixed(1)}s`
33+
}
5234

53-
execSync('pnpm --filter @instructure/ui-icons prepare-build', opts)
54-
55-
// Executes a ui-codemods script to generate a versioned components list
56-
// from the ui metapackage's latest re-export file. This is required for
57-
// the updateInstUIImportVersions codemod's diagnose mode.
58-
execSync(
59-
'pnpm --filter @instructure/ui-codemods generate:versioned-exports',
60-
opts
61-
)
62-
63-
console.info('Building packages with Babel...')
64-
try {
65-
execSync('pnpm run build', opts)
66-
} catch (error) {
67-
console.error("'pnpm run build' failed", error)
68-
process.exit(1)
35+
function mark(name) {
36+
console.log(`\n================================================`)
37+
console.log(`${name}...`)
38+
if (steps.length) {
39+
steps[steps.length - 1].duration =
40+
Date.now() - steps[steps.length - 1].start
6941
}
42+
steps.push({ name, start: Date.now(), duration: 0 })
43+
}
7044

71-
console.info('Generating tokens...')
72-
try {
73-
execSync('pnpm run build:tokens', opts)
74-
} catch (error) {
75-
console.error("'pnpm run build:tokens' failed", error)
76-
process.exit(1)
77-
}
45+
const steps = []
46+
const bootstrapStart = Date.now()
7847

79-
console.info('Building TypeScript declarations...')
80-
try {
81-
execSync('pnpm run build:types', opts)
82-
} catch (error) {
83-
console.error("'pnpm run build:types' failed", error)
84-
process.exit(1)
85-
}
86-
}
48+
mark('Deleting build artifacts')
49+
execSync(path.resolve('scripts/clean.js'), opts)
8750

88-
function bootstrap() {
89-
execSync(path.resolve('scripts/clean.js'), opts)
90-
buildProject()
91-
}
51+
mark('Fetching design tokens')
52+
execSync(
53+
'pnpm --filter @instructure/ui-scripts update @instructure/instructure-design-tokens',
54+
opts
55+
)
56+
57+
mark('Building themes')
58+
execSync('pnpm run build:themes', opts)
9259

93-
bootstrap()
60+
mark('Preparing icons')
61+
execSync('pnpm --filter @instructure/ui-icons prepare-build', opts)
62+
63+
mark('Generating package list for codemods')
64+
execSync(
65+
'pnpm --filter @instructure/ui-codemods generate:versioned-exports',
66+
opts
67+
)
68+
69+
mark('Building packages with Babel')
70+
execSync('pnpm run build', opts)
71+
72+
mark('Generating design tokens')
73+
execSync('pnpm run build:tokens', opts)
74+
75+
mark('Building TypeScript declarations')
76+
execSync('pnpm run build:types', opts)
77+
78+
// Log build time summary. Assumes that the build is not parallel
79+
steps[steps.length - 1].duration = Date.now() - steps[steps.length - 1].start
80+
81+
const total = Date.now() - bootstrapStart
82+
const nameW = Math.max(...steps.map((s) => s.name.length))
83+
const durW = Math.max(
84+
...steps.map((s) => format(s.duration).length),
85+
format(total).length
86+
)
87+
const tableWidth = nameW + durW + 7
88+
89+
console.log('\n' + '='.repeat(tableWidth))
90+
console.log(' Bootstrap Summary')
91+
console.log('='.repeat(tableWidth))
92+
for (const s of steps) {
93+
console.log(` ${s.name.padEnd(nameW)} ${format(s.duration).padStart(durW)}`)
94+
}
95+
console.log('-'.repeat(tableWidth))
96+
console.log(` ${'Total'.padEnd(nameW)} ${format(total).padStart(durW)}`)
97+
console.log('='.repeat(tableWidth))

scripts/clean.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ const path = require('path')
2828
const { execSync } = require('child_process')
2929

3030
const NODE_PACKAGES = [
31-
'ui-icons-build',
3231
'ui-babel-preset',
3332
'ui-codemods',
3433
'ui-scripts',
3534
'command-utils',
36-
'instui-cli',
3735
'babel-plugin-transform-imports',
3836
'pkg-utils'
3937
]
@@ -61,7 +59,7 @@ async function deleteDirs(dirs = []) {
6159
)
6260
}
6361

64-
// deletes built files from tooling packages (NODE_PACKAGES const)
62+
// deletes build artifacts from all packages
6563
async function clean() {
6664
const packagesPath = path.resolve('./packages')
6765
const packageDirs = await fs.readdir(packagesPath, { withFileTypes: true })
@@ -88,7 +86,7 @@ async function clean() {
8886
function removeNodeModules() {
8987
try {
9088
// Use native find command - 10-100x faster than Node.js recursive scan
91-
console.error('Finding node_modules directories...')
89+
console.info('Finding node_modules directories...')
9290
execSync(
9391
'find . -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null || true',
9492
{ stdio: 'inherit' }
@@ -100,17 +98,17 @@ function removeNodeModules() {
10098
}
10199

102100
async function main() {
103-
console.error('Deleting built files from tooling packages...')
101+
console.info('Deleting build artifacts...')
104102
await clean()
105103

106104
const args = process.argv.slice(2)
107105
if (args.length > 0 && args[0] === '--nuke_node') {
108-
console.error('Deleting node_modules recursively...')
106+
console.info('Deleting node_modules recursively...')
109107
removeNodeModules()
110108
}
111109
}
112110

113111
main().catch((error) => {
114-
console.error('Clean script failed:', error)
112+
console.info('clean.js failed:', error)
115113
process.exit(1)
116114
})

0 commit comments

Comments
 (0)