Skip to content

Commit 67b9879

Browse files
m-absNathanWalker
authored andcommitted
fix(schematics): the nx format patch didn't work for all xplat-files (#6)
1 parent 810e7bc commit 67b9879

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

scripts/postinstall.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ updateConfig();
2929

3030
export function fixFormatter() {
3131
const formatPath = path.join(process.cwd(), '/../..', '@nrwl/schematics/src/command-line/format.js');
32-
// console.log('formatPath:', formatPath);
3332
let formatContent = fs.readFileSync(formatPath, 'UTF-8');
34-
const patchLine = ` patterns.push("xplat\/**\/*.ts", "!apps/**/platforms/{android,ios}/**/*.ts");`;
33+
34+
// Old patch line, globs should've been wrapped in quotes.
35+
const oldPatchLine = ` patterns.push("xplat\/**\/*.ts", "!apps/**/platforms/{android,ios}/**/*.ts");`;
36+
const patchLine = ` patterns.push("\"xplat\/**\/*.ts\"", "\"!apps/**/platforms/{android,ios}/**/*.ts\"");`;
37+
if (formatContent.indexOf(oldPatchLine) !== -1) {
38+
console.log('Old patch for nx format have been applied, replace with new patch');
39+
fs.writeFileSync(formatPath, formatContent.replace(oldPatchLine, patchLine));
40+
return;
41+
}
42+
3543
if (formatContent.indexOf(patchLine) !== -1) {
3644
console.log(`Patch for nx format have already been applied`);
3745
return;
@@ -45,6 +53,7 @@ export function fixFormatter() {
4553
const newFormatContent = formatContent.replace(patchRegExp, `$1\n${patchLine}\n$2`);
4654
if (formatContent !== newFormatContent) {
4755
fs.writeFileSync(formatPath, newFormatContent);
56+
console.log('Patch for nx format have been applied');
4857
} else {
4958
throw new Error(`Apply couldn't patch for nx format`);
5059
}

0 commit comments

Comments
 (0)