Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"git-raw-commits>dargs": "Force dargs@7.0.0 (CommonJS) for git-raw-commits@3.0.0 used by lerna. pnpm hoisting was causing ESM dargs@8.1.0 to be resolved instead, breaking 'pnpm run bump' with 'TypeError: dargs is not a function'"
},
"engines": {
"node": ">=22",
"node": ">=22.18.0",
"npm": "Use pnpm instead.",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 22.18+ can natively run .ts files without the --experimental-strip-types flag, so it engines.node so it was bumped >=22.18.0 to enforce the minimum.

"pnpm": ">=10"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/command-utils/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Command {
/**
* @param bin {string} The binary name, e.g. `pwd`
* @param args {string[]} command arguments
* @param envVars {Object.<string, string>} Environment variables
* @param [envVars] {Object.<string, string>} Environment variables

@ToMESSKa ToMESSKa Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

babel.ts calls getCommand(specifyCJSFormat, []) with only 2 arguments — after the TS conversion TypeScript started enforcing the JSDoc that said all 3 args were required, so I marked the 3rd one optional.

*/
function getCommand(bin, args, envVars) {
return new Command(bin, args, envVars)
Expand Down
4 changes: 4 additions & 0 deletions packages/pkg-utils/lib/get-changed-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const path = require('path')
const getPackages = require('./get-packages')
const childProcess = require('child_process')

/**
* @param [commitIsh] {string}
* @param [allPackages] {any[]}
*/

@ToMESSKa ToMESSKa Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm.ts calls pkgUtils.getChangedPackages() with no arguments — after the TS conversion TypeScript started enforcing the JSDoc that said all 2 args were required, so I marked them optional.

module.exports = function getChangedPackages(
commitIsh = 'HEAD^1',
allPackages
Expand Down
5 changes: 4 additions & 1 deletion packages/pkg-utils/lib/get-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ const path = require('path')
const readPkgUp = require('read-pkg-up')
const Package = require('@lerna/package').Package

/**
* @param [options] {readPkgUp.NormalizeOptions}
*/

@ToMESSKa ToMESSKa Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm.ts calls pkgUtils.getPackage() with no arguments — after the TS conversion TypeScript started enforcing the JSDoc that said the arg was required, so I marked it optional.

exports.getPackage = function getPackage(options) {
const result = readPackage(options)
return new Package(result.packageJson, path.dirname(result.path))
}

/**
* Reads a package.json
* @param options {readPkgUp.NormalizeOptions}
* @param [options] {readPkgUp.NormalizeOptions}
* @returns {readPkgUp.NormalizedPackageJson}

@ToMESSKa ToMESSKa Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump.ts, publish.ts, tag.ts, and deprecate.ts all call pkgUtils.getPackageJSON() with no arguments — after the TS conversion TypeScript started enforcing the JSDoc options as required, so I marked it optional.

*/
exports.getPackageJSON = function getPackageJSON(options) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "ui-scripts lint",
"lint:fix": "ui-scripts lint --fix",
"ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false",
"generate:versioned-exports": "node --experimental-strip-types scripts/generateVersionedExports.ts"
"generate:versioned-exports": "node scripts/generateVersionedExports.ts"
},

@ToMESSKa ToMESSKa Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 22.18+ can natively run .ts files without the --experimental-strip-types flag, so it was removed it from packages/ui-scripts/lib/index.ts, packages/ui-codemods/package.json, and the packages/ui-codemods/scripts/generateVersionedExports.ts. I also bumped engines.node in the root package.json to >=22.18.0 to enforce the minimum.

"license": "MIT",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-codemods/scripts/generateVersionedExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* Generates a list of all versioned components based on the @instructure/ui meta package
* Run with: node --experimental-strip-types scripts/generateVersionedExports.ts
* Run with: node scripts/generateVersionedExports.ts
* from the packages/ui-codemods directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 22.18+ can natively run .ts files without the --experimental-strip-types flag, so it was removed it from packages/ui-scripts/lib/index.ts, packages/ui-codemods/package.json, and the packages/ui-codemods/scripts/generateVersionedExports.ts. I also bumped engines.node in the root package.json to >=22.18.0 to enforce the minimum.

*/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import { describe, it, expect } from 'vitest'
import { fuzzyMatch } from '../commands/create-component-version.ts'

const components = [
{ label: '', dir: '', pkg: 'ui-buttons', name: 'Button', versions: ['v1'] },
{ label: '', dir: '', pkg: 'ui-text', name: 'Text', versions: ['v1'] },
{ label: '', dir: '', pkg: 'ui-tabs', name: 'Tabs', versions: ['v1', 'v2'] },
{
label: '',
dir: '',
pkg: 'ui-buttons',
name: 'IconButton',
versions: ['v1']
}
]

describe('fuzzyMatch', () => {
it('matches when the query is a substring of pkg or name', () => {
expect(
fuzzyMatch(components, 'button')
.map((c) => c.name)
.sort()
).toEqual(['Button', 'IconButton'])
})

it('matches characters in order even when they are not contiguous', () => {
const matches = fuzzyMatch(components, 'utt').map((c) => c.name)
expect(matches).toContain('Button')
})

it('is case-insensitive', () => {
expect(
fuzzyMatch(components, 'BUTTON')
.map((c) => c.name)
.sort()
).toEqual(['Button', 'IconButton'])
})

it('returns an empty array when no component matches', () => {
expect(fuzzyMatch(components, 'xyz')).toEqual([])
})

it('returns every component for an empty query string', () => {
expect(fuzzyMatch(components, '')).toHaveLength(components.length)
})

it('considers both pkg and name when scoring (ordered chars)', () => {
const matches = fuzzyMatch(components, 'tabt').map((c) => c.name)
expect(matches).toContain('Tabs')
})
})
87 changes: 87 additions & 0 deletions packages/ui-scripts/lib/__node_tests__/createFile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import { describe, it, expect, afterEach } from 'vitest'
import {
existsSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync
} from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import createFile from '../build/buildThemes/createFile.ts'

describe('createFile', () => {
let dir: string

afterEach(() => {
if (dir) rmSync(dir, { recursive: true, force: true })
})

it('writes a file with the license header prepended to the content', async () => {
dir = mkdtempSync(join(tmpdir(), 'create-file-')) + '/'
const target = dir + 'output.ts'

await createFile(target, 'export const x = 1')

const written = readFileSync(target, 'utf-8')
expect(written).toContain('The MIT License (MIT)')
expect(written).toContain('export const x = 1')
expect(written.indexOf('The MIT License')).toBeLessThan(
written.indexOf('export const x = 1')
)
})

it('creates missing parent directories', async () => {
dir = mkdtempSync(join(tmpdir(), 'create-file-')) + '/'
const target = dir + 'deeply/nested/output.ts'

await createFile(target, 'hello')

expect(existsSync(target)).toBe(true)
})

it('overwrites an existing file at the same path', async () => {
dir = mkdtempSync(join(tmpdir(), 'create-file-')) + '/'
const target = dir + 'output.ts'

writeFileSync(target, 'old content', 'utf-8')

await createFile(target, 'new content')

const written = readFileSync(target, 'utf-8')
expect(written).toContain('new content')
expect(written).not.toContain('old content')
})

it('does not throw when the target does not already exist', async () => {
dir = mkdtempSync(join(tmpdir(), 'create-file-')) + '/'
const target = dir + 'output.ts'

// The function tries to unlink first — ENOENT must be swallowed
await expect(createFile(target, 'hello')).resolves.not.toThrow()
})
})
108 changes: 108 additions & 0 deletions packages/ui-scripts/lib/__node_tests__/generate-custom-index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import { describe, it, expect, afterEach, vi } from 'vitest'
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import generateCustomIndex from '../icons/generate-custom-index.ts'

describe('generateCustomIndex', () => {
let dir: string

afterEach(() => {
if (dir) rmSync(dir, { recursive: true, force: true })
vi.restoreAllMocks()
})

function setupFixtures() {
dir = mkdtempSync(join(tmpdir(), 'gen-custom-')) + '/'
mkdirSync(dir + 'svg/Custom', { recursive: true })
writeFileSync(
dir + 'svg/Custom/ai-info.svg',
'<svg viewBox="0 0 24 24"><path d="M0,0" fill="currentColor"/></svg>'
)
writeFileSync(
dir + 'svg/Custom/canvas-logo.svg',
'<svg viewBox="0 0 32 32"><circle cx="16" cy="16" r="8"/></svg>'
)
vi.spyOn(process, 'cwd').mockReturnValue(dir.slice(0, -1))
vi.spyOn(console, 'log').mockImplementation(() => {})
}

it('writes one InstUIIcon export per SVG file', () => {
setupFixtures()
generateCustomIndex()
const content = readFileSync(
dir + 'src/generated/custom/index.tsx',
'utf-8'
)
const exportCount = (content.match(/^export const /gm) || []).length
expect(exportCount).toBe(2)
})

it('converts kebab-case filenames to PascalCase icon names', () => {
setupFixtures()
generateCustomIndex()
const content = readFileSync(
dir + 'src/generated/custom/index.tsx',
'utf-8'
)
expect(content).toContain('export const AiInfoInstUIIcon')
expect(content).toContain('export const CanvasLogoInstUIIcon')
})

it('forwards the SVG viewBox to wrapCustomIcon', () => {
setupFixtures()
generateCustomIndex()
const content = readFileSync(
dir + 'src/generated/custom/index.tsx',
'utf-8'
)
expect(content).toContain(
"wrapCustomIcon(AiInfoPaths, 'AiInfo', '0 0 24 24')"
)
expect(content).toContain(
"wrapCustomIcon(CanvasLogoPaths, 'CanvasLogo', '0 0 32 32')"
)
})

it('rewrites fill="currentColor" to ={color} so consumers can theme the icon', () => {
setupFixtures()
generateCustomIndex()
const content = readFileSync(
dir + 'src/generated/custom/index.tsx',
'utf-8'
)
expect(content).toContain('fill={color}')
expect(content).not.toContain('fill="currentColor"')
})

it('throws if the svg/Custom directory does not exist', () => {
dir = mkdtempSync(join(tmpdir(), 'gen-custom-')) + '/'
vi.spyOn(process, 'cwd').mockReturnValue(dir.slice(0, -1))
vi.spyOn(console, 'log').mockImplementation(() => {})
expect(() => generateCustomIndex()).toThrow(/SVG directory not found/)
})
})
Loading
Loading