-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into ido/cli-flakiness
- Loading branch information
Showing
54 changed files
with
1,524 additions
and
902 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,29 @@ | ||
import { parseNamespace } from '@stylable/core/dist/features/st-namespace'; | ||
import type * as postcss from 'postcss'; | ||
import type { CodeMod } from './types'; | ||
|
||
export const namespaceToStNamespace: CodeMod = ({ ast }) => { | ||
let changed = false; | ||
let foundStNamespace = false; | ||
const nodesToMod: postcss.AtRule[] = []; | ||
ast.walkAtRules((atRule) => { | ||
if (atRule.name === 'namespace') { | ||
const namespace = parseNamespace(atRule); | ||
if (namespace) { | ||
nodesToMod.push(atRule); | ||
} | ||
} else if (atRule.name === 'st-namespace') { | ||
foundStNamespace = true; | ||
} | ||
}); | ||
if (!foundStNamespace) { | ||
for (const atRule of nodesToMod) { | ||
atRule.name = 'st-namespace'; | ||
changed = true; | ||
} | ||
} | ||
|
||
return { | ||
changed, | ||
}; | ||
}; |
58 changes: 58 additions & 0 deletions
58
packages/cli/test/codemods/namespace-to-st-namespace.spec.ts
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,58 @@ | ||
import { expect } from 'chai'; | ||
import { | ||
populateDirectorySync, | ||
loadDirSync, | ||
runCliCodeMod, | ||
createTempDirectory, | ||
ITempDirectory, | ||
} from '@stylable/e2e-test-kit'; | ||
|
||
describe('CLI Codemods namespace-to-st-namespace', () => { | ||
let tempDir: ITempDirectory; | ||
|
||
beforeEach(async () => { | ||
tempDir = await createTempDirectory(); | ||
}); | ||
afterEach(async () => { | ||
await tempDir.remove(); | ||
}); | ||
|
||
it('should replace @namespace with @st-namespace', () => { | ||
populateDirectorySync(tempDir.path, { | ||
'package.json': `{"name": "test", "version": "0.0.0"}`, | ||
'style.st.css': `@namespace "button";`, | ||
}); | ||
|
||
runCliCodeMod(['--rootDir', tempDir.path, '--mods', 'namespace-to-st-namespace']); | ||
|
||
const dirContent = loadDirSync(tempDir.path); | ||
|
||
expect(dirContent['style.st.css']).equal('@st-namespace "button";'); | ||
}); | ||
it('should not replace @namespace when @st-namespace already exist', () => { | ||
populateDirectorySync(tempDir.path, { | ||
'package.json': `{"name": "test", "version": "0.0.0"}`, | ||
'style.st.css': `@namespace "button"; @st-namespace "comp";`, | ||
}); | ||
|
||
runCliCodeMod(['--rootDir', tempDir.path, '--mods', 'namespace-to-st-namespace']); | ||
|
||
const dirContent = loadDirSync(tempDir.path); | ||
|
||
expect(dirContent['style.st.css']).equal('@namespace "button"; @st-namespace "comp";'); | ||
}); | ||
it('should not replace @namespace that would not be used as @st-namespace', () => { | ||
populateDirectorySync(tempDir.path, { | ||
'package.json': `{"name": "test", "version": "0.0.0"}`, | ||
'style.st.css': `@namespace "http://button"; @namespace prefix "btn";`, | ||
}); | ||
|
||
runCliCodeMod(['--rootDir', tempDir.path, '--mods', 'namespace-to-st-namespace']); | ||
|
||
const dirContent = loadDirSync(tempDir.path); | ||
|
||
expect(dirContent['style.st.css']).equal( | ||
'@namespace "http://button"; @namespace prefix "btn";' | ||
); | ||
}); | ||
}); |
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
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
Oops, something went wrong.