Skip to content

Commit 260068b

Browse files
authored
fix(WC): update themes import paths to licensed version (#1387)
1 parent 1846e1a commit 260068b

File tree

2 files changed

+85
-7
lines changed

2 files changed

+85
-7
lines changed

packages/core/update/Update.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
1313
let guideLink = "";
1414
let logicFilesExtension = "";
1515
let styleExtensions = [];
16+
let shouldUpgradeHTML = false;
1617

1718
const config = ProjectConfig.getConfig();
1819
const framework = config.project.framework;
@@ -31,6 +32,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
3132
case "webcomponents":
3233
guideLink = "https://www.infragistics.com/products/ignite-ui-web-components/web-components/components/general-licensing";
3334
logicFilesExtension = "ts";
35+
shouldUpgradeHTML = true;
3436
break;
3537
default:
3638
break;
@@ -61,8 +63,16 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
6163
const logicFiles = [];
6264
const styleFiles = [];
6365
const pkgJsonFiles = [];
66+
const htmlFiles = [];
6467
pkgJsonFiles.push(...fs.glob(rootPath, `package.json`, ['node_modules', 'dist']));
6568

69+
if (shouldUpgradeHTML) {
70+
const filePaths = fs.glob(rootPath, `*.html`, ['node_modules', 'dist']);
71+
if (filePaths && filePaths.length > 0) {
72+
htmlFiles.push(...filePaths);
73+
}
74+
}
75+
6676
let workspaceConfig = null;
6777
switch (framework.toLowerCase()) {
6878
case "angular":
@@ -106,6 +116,9 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
106116
}
107117

108118
updateFileImports(logicFiles, styleFiles, upgradeable, fs);
119+
if (shouldUpgradeHTML) {
120+
updateHTMLImports(htmlFiles, upgradeable, fs);
121+
}
109122
updatePackageJsonFiles(pkgJsonFiles, upgradeable, fs);
110123
createNpmrc(rootPath, fs);
111124
updateWorkflows(fs);
@@ -149,8 +162,11 @@ function updateFileImports(
149162
let fileChange = false;
150163
for (const packageDef of packageDefs) {
151164
if (fileContent.includes(packageDef.trial)) {
152-
const newContent = updateFileContent(fileContent,
153-
createExpressions(RegularExpressionType.LOGIC, packageDef.trial), packageDef.licensed);
165+
// Because when including a theme inside a WC render method we need to update its import path too #1386
166+
const regExpressions = [...createExpressions(RegularExpressionType.LOGIC, packageDef.trial),
167+
...createExpressions(RegularExpressionType.STYLE, packageDef.trial)
168+
]
169+
const newContent = updateFileContent(fileContent, regExpressions, packageDef.licensed);
154170
fileChange = fileContent !== newContent;
155171
fileContent = newContent;
156172
}
@@ -231,3 +247,21 @@ function createNpmrc(
231247
fs.writeFile(npmrcPath, fileContent);
232248
}
233249
}
250+
251+
function updateHTMLImports(htmlFiles: string[], packageDefs: PackageDefinition[], fs: IFileSystem): void {
252+
for (const file of htmlFiles) {
253+
let fileContent = fs.readFile(file);
254+
let fileChange = false;
255+
for (const packageDef of packageDefs) {
256+
if (fileContent.includes(packageDef.trial)) {
257+
const newContent = updateFileContent(fileContent,
258+
createExpressions(RegularExpressionType.STYLE, packageDef.trial), packageDef.licensed);
259+
fileChange = fileContent !== newContent;
260+
fileContent = newContent;
261+
}
262+
}
263+
if (fileChange) {
264+
fs.writeFile(file, fileContent);
265+
}
266+
}
267+
}

spec/unit/update-spec.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ export default function Home() {
806806
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
807807
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
808808
([ "package.json" ], // root package.json
809+
[], //index.html
809810
[], // logic files
810811
[ "./project/package.json" ]); // inner package.json files
811812
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
@@ -827,7 +828,7 @@ export default function Home() {
827828
}
828829
}));
829830
expect(fsSpy.writeFile).toHaveBeenCalledTimes(2);
830-
expect(fsSpy.glob).toHaveBeenCalledTimes(3);
831+
expect(fsSpy.glob).toHaveBeenCalledTimes(4);
831832
});
832833

833834
it("Should update import paths in files correctly", async () => {
@@ -839,6 +840,7 @@ export default function Home() {
839840
"dependencies": {
840841
"igniteui-webcomponents": "^4.7.0",
841842
"igniteui-webcomponents-core": "^4.7.0",
843+
"igniteui-webcomponents-grids": "^4.7.0",
842844
"igniteui-dockmanager": "^1.0.0",
843845
"some-package": "^0.0.0"
844846
}
@@ -849,6 +851,7 @@ export default function Home() {
849851
"dependencies": {
850852
"@infragistics/igniteui-dockmanager": "^1.0.0",
851853
"@infragistics/igniteui-webcomponents-core": "^4.7.0",
854+
"@infragistics/igniteui-webcomponents-grids": "^4.7.0",
852855
"igniteui-webcomponents": "^4.7.0",
853856
"some-package": "^0.0.0"
854857
}
@@ -874,7 +877,8 @@ import { ModuleManager } from '@infragistics/igniteui-webcomponents-core';
874877
875878
export default class App extends LitElement {
876879
const title = 'igniteui-webcomponents example';
877-
}`}, {
880+
}`},
881+
{
878882
path: ".github/workflows/node.js.yml",
879883
content:
880884
`# start content
@@ -903,9 +907,48 @@ export default class App extends LitElement {
903907
- run: echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
904908
- run: npm i # replace with 'npm ci' after committing lock file from first install
905909
# end content
906-
`}];
910+
`},
911+
{
912+
path: "index.html",
913+
content:
914+
`<!doctype html>
915+
<html lang="en-GB">
916+
<head>
917+
<meta charset="utf-8">
918+
<base href="/">
919+
<title>Ignite UI for Web Components</title>
920+
<link rel="stylesheet" href="./node_modules/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css">
921+
<link rel="stylesheet" href="./styles.css">
922+
</head>
923+
<body class="ig-scrollbar">
924+
<app-root></app-root>
925+
926+
<script type="module" src="./dist/src/index.js"></script>
927+
</body>
928+
</html>
929+
`,
930+
expected:
931+
`<!doctype html>
932+
<html lang="en-GB">
933+
<head>
934+
<meta charset="utf-8">
935+
<base href="/">
936+
<title>Ignite UI for Web Components</title>
937+
<link rel="stylesheet" href="./node_modules/@infragistics/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css">
938+
<link rel="stylesheet" href="./styles.css">
939+
</head>
940+
<body class="ig-scrollbar">
941+
<app-root></app-root>
942+
943+
<script type="module" src="./dist/src/index.js"></script>
944+
</body>
945+
</html>
946+
`
947+
948+
},];
907949
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
908950
([ "package.json" ], // root package.json
951+
["index.html"], // html file
909952
["src/app.ts"], // logic files
910953
[]); // inner package.json files
911954
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
@@ -921,7 +964,7 @@ export default class App extends LitElement {
921964
for (const fileEntry of mockFileArray) {
922965
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
923966
}
924-
expect(fsSpy.glob).toHaveBeenCalledTimes(3);
967+
expect(fsSpy.glob).toHaveBeenCalledTimes(4);
925968
});
926969

927970
it("Should update package.json files from workspaces", async () => {
@@ -1012,6 +1055,7 @@ export default class App extends LitElement {
10121055
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
10131056
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
10141057
([ "package.json" ], // root package.json
1058+
[], //index.html
10151059
[], // projectA logic files
10161060
[ "./projectA/package.json" ], // projectA package.json
10171061
[], // projectB logic files
@@ -1031,7 +1075,7 @@ export default class App extends LitElement {
10311075
for (const fileEntry of mockFileArray) {
10321076
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
10331077
}
1034-
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
1078+
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
10351079
});
10361080
});
10371081
});

0 commit comments

Comments
 (0)