-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Merge prerelease/minor into prerelease/major
- Loading branch information
Showing
360 changed files
with
10,306 additions
and
4,762 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// @ts-check | ||
const {getOptions} = require('loader-utils'); | ||
const {transform} = require('@workday/canvas-kit-styling-transform/testing'); | ||
|
||
/** @typedef {import('webpack').loader.Loader} Loader */ | ||
/** @typedef {import('webpack').loader.LoaderContext} LoaderContext */ | ||
|
||
// Tracks files that have been processed. If a file is already processed, it | ||
// means the file has been updated and we need to update the Typescript program | ||
// so the changes are reflected in our doc output. If we don't update the TS | ||
// program, the docs will be processed with the outdated cache of the file | ||
// contents. | ||
const filesProcessedMap = new Map(); | ||
|
||
/** | ||
* @this {LoaderContext} | ||
* @param {Parameters<Loader>[0]} source | ||
*/ | ||
function styleTransformLoader(source) { | ||
const { | ||
/** @type {any} */ | ||
Doc, | ||
} = getOptions(this); | ||
|
||
if (filesProcessedMap.has(this.resourcePath)) { | ||
Doc.update(); | ||
} | ||
filesProcessedMap.set(this.resourcePath, true); | ||
|
||
return transform(Doc.program, this.resourcePath); | ||
} | ||
|
||
module.exports = styleTransformLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Transform} from 'jscodeshift'; | ||
|
||
import renameHasErrorPreview from './renameHasErrorPreview'; | ||
import replaceStylesIconProp from './replaceStylesIconProp'; | ||
|
||
const transform: Transform = (file, api, options) => { | ||
// These will run in order. If your transform depends on others, place yours after dependent transforms | ||
const fixes = [ | ||
// add codemods here | ||
renameHasErrorPreview, | ||
replaceStylesIconProp, | ||
]; | ||
return fixes.reduce((source, fix) => fix({...file, source}, api, options) as string, file.source); | ||
}; | ||
|
||
export default transform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {API, FileInfo, Options, JSXOpeningElement, JSXIdentifier} from 'jscodeshift'; | ||
import {hasImportSpecifiers} from '../v6/utils'; | ||
import {getImportRenameMap} from './utils/getImportRenameMap'; | ||
const textInputPackage = '@workday/canvas-kit-preview-react/text-input'; | ||
const textAreaPackage = '@workday/canvas-kit-preview-react/text-area'; | ||
const formFieldPackage = '@workday/canvas-kit-preview-react/form-field'; | ||
const packages = [textInputPackage, textAreaPackage, formFieldPackage]; | ||
const packageImports = ['TextInput', 'FormField', 'TextArea']; | ||
|
||
export default function transformer(file: FileInfo, api: API, options: Options) { | ||
const j = api.jscodeshift; | ||
|
||
const root = j(file.source); | ||
|
||
// exit if the named imports aren't found | ||
if (!hasImportSpecifiers(api, root, packages, packageImports)) { | ||
return file.source; | ||
} | ||
|
||
// getImportRenameMap utility will tell us if the file containsCanvasImports | ||
// and give us an importMap to track what identifiers we need to update | ||
const {importMap, styledMap} = getImportRenameMap(j, root, '@workday/canvas-kit-preview-react'); | ||
|
||
root | ||
.find(j.JSXOpeningElement, (value: JSXOpeningElement) => { | ||
const isCorrectImport = Object.entries(importMap).some( | ||
([original, imported]) => | ||
imported === (value.name as JSXIdentifier).name && packageImports.includes(original) | ||
); | ||
|
||
const isCorrectStyled = Object.entries(styledMap).some( | ||
([original, styled]) => | ||
styled === (value.name as JSXIdentifier).name && packageImports.includes(original) | ||
); | ||
|
||
return isCorrectImport || isCorrectStyled; | ||
}) | ||
.forEach(nodePath => { | ||
nodePath.node.attributes?.forEach(attr => { | ||
if (attr.type === 'JSXAttribute') { | ||
if (attr.name.name === 'hasError') { | ||
attr.name.name = 'error'; | ||
if (attr.value && attr.value.type === 'JSXExpressionContainer') { | ||
const value = attr.value.expression as any; | ||
|
||
if (value.type === 'BooleanLiteral') { | ||
if (value.value) { | ||
attr.value = j.stringLiteral('error'); | ||
} else { | ||
attr.value = j.jsxExpressionContainer(j.identifier('undefined')); | ||
} | ||
} else if (value.type === 'Identifier') { | ||
attr.value.expression = j.conditionalExpression( | ||
j.identifier(value.name), | ||
j.stringLiteral('error'), | ||
j.identifier('undefined') | ||
); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return root.toSource(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {API, FileInfo, Options, JSXOpeningElement, JSXIdentifier} from 'jscodeshift'; | ||
import {hasImportSpecifiers} from '../v6/utils'; | ||
import {getImportRenameMap} from './utils/getImportRenameMap'; | ||
|
||
const packages = ['@workday/canvas-kit-react', '@workday/canvas-kit-react/icon']; | ||
const packageImports = ['Svg', 'SystemIcon', 'AccentIcon']; | ||
|
||
export default function transformer(file: FileInfo, api: API, options: Options) { | ||
const j = api.jscodeshift; | ||
|
||
const root = j(file.source); | ||
|
||
// exit if the named imports aren't found | ||
if (!hasImportSpecifiers(api, root, packages, packageImports)) { | ||
return file.source; | ||
} | ||
|
||
// getImportRenameMap utility will tell us if the file containsCanvasImports | ||
// and give us an importMap to track what identifiers we need to update | ||
const {importMap, styledMap} = getImportRenameMap( | ||
j, | ||
root, | ||
'@workday/canvas-kit-react', | ||
'@workday/canvas-kit-react/icon' | ||
); | ||
|
||
root | ||
.find(j.JSXOpeningElement, (value: JSXOpeningElement) => { | ||
const isCorrectImport = Object.entries(importMap).some( | ||
([original, imported]) => | ||
imported === (value.name as JSXIdentifier).name && packageImports.includes(original) | ||
); | ||
|
||
const isCorrectStyled = Object.entries(styledMap).some( | ||
([original, styled]) => | ||
styled === (value.name as JSXIdentifier).name && packageImports.includes(original) | ||
); | ||
|
||
return isCorrectImport || isCorrectStyled; | ||
}) | ||
.forEach(nodePath => { | ||
nodePath.node.attributes?.forEach(attr => { | ||
if (attr.type === 'JSXAttribute') { | ||
if (attr.name.name === 'styles') { | ||
attr.name.name = 'cs'; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return root.toSource(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {runInlineTest} from 'jscodeshift/dist/testUtils'; | ||
|
||
export const expectTransformFactory = | ||
(fn: Function) => (input: string, expected: string, options?: Record<string, any>) => { | ||
return runInlineTest(fn, options, {source: input}, expected, {parser: 'tsx'}); | ||
}; |
Oops, something went wrong.