@react-native-windows/codegen
Advanced tools
Comparing version 0.0.0-canary.9 to 0.0.0-canary.10
@@ -5,6 +5,36 @@ { | ||
{ | ||
"date": "Fri, 11 Jun 2021 05:06:57 GMT", | ||
"date": "Thu, 05 Aug 2021 05:06:38 GMT", | ||
"tag": "@react-native-windows/codegen_v0.0.0-canary.10", | ||
"version": "0.0.0-canary.10", | ||
"comments": { | ||
"prerelease": [ | ||
{ | ||
"comment": "Do not write codegen files if the contents have not changed, as this breaks incremental builds", | ||
"author": "30809111+acoates-ms@users.noreply.github.com", | ||
"commit": "3b92733ab97670e6eb2d944f65ff341994e80517", | ||
"package": "@react-native-windows/codegen" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Sat, 24 Jul 2021 05:05:52 GMT", | ||
"tag": "@react-native-windows/codegen_v0.0.0-canary.9", | ||
"version": "0.0.0-canary.9", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Replace @rnw-scripts/jest-out-of-tree-resolver with @rnx-kit/jest-resolver", | ||
"author": "4123478+tido64@users.noreply.github.com", | ||
"commit": "a311022ebc0c1d8070d7e54312197f486c470d33", | ||
"package": "@react-native-windows/codegen" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Fri, 11 Jun 2021 05:08:55 GMT", | ||
"tag": "@react-native-windows/codegen_v0.0.0-canary.9", | ||
"version": "0.0.0-canary.9", | ||
"comments": { | ||
"patch": [ | ||
@@ -11,0 +41,0 @@ { |
# Change Log - @react-native-windows/codegen | ||
This log was last generated on Fri, 11 Jun 2021 05:06:57 GMT and should not be manually modified. | ||
This log was last generated on Thu, 05 Aug 2021 05:06:38 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 0.0.0-canary.10 | ||
Thu, 05 Aug 2021 05:06:38 GMT | ||
### Changes | ||
- Do not write codegen files if the contents have not changed, as this breaks incremental builds (30809111+acoates-ms@users.noreply.github.com) | ||
## 0.0.0-canary.9 | ||
Fri, 11 Jun 2021 05:06:57 GMT | ||
Fri, 11 Jun 2021 05:08:55 GMT | ||
@@ -11,0 +19,0 @@ ### Patches |
{ | ||
"name": "@react-native-windows/codegen", | ||
"version": "0.0.0-canary.9", | ||
"version": "0.0.0-canary.10", | ||
"description": "Generators for react-native-codegen targeting react-native-windows", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
119
src/Cli.ts
@@ -82,2 +82,13 @@ /** | ||
function normalizeFileMap( | ||
map: Map<string, string>, | ||
outputDir: string, | ||
outMap: Map<string, string>, | ||
): void { | ||
for (const [fileName, contents] of map) { | ||
const location = path.join(outputDir, fileName); | ||
outMap.set(path.normalize(location), contents); | ||
} | ||
} | ||
function checkFilesForChanges( | ||
@@ -89,5 +100,16 @@ map: Map<string, string>, | ||
for (const [contents, fileName] of map) { | ||
const location = path.join(outputDir, fileName); | ||
if (!fs.existsSync(location)) { | ||
const allExistingFiles = globby | ||
.sync(`${outputDir}/**`) | ||
.map(_ => path.normalize(_)) | ||
.sort(); | ||
const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort(); | ||
if ( | ||
allExistingFiles.length !== allGeneratedFiles.length || | ||
!allExistingFiles.every((val, index) => val === allGeneratedFiles[index]) | ||
) | ||
return true; | ||
for (const [fileName, contents] of map) { | ||
if (!fs.existsSync(fileName)) { | ||
hasChanges = true; | ||
@@ -97,3 +119,3 @@ continue; | ||
const currentContents = fs.readFileSync(location, 'utf8'); | ||
const currentContents = fs.readFileSync(fileName, 'utf8'); | ||
if (currentContents !== contents) { | ||
@@ -111,12 +133,29 @@ console.error(`- ${fileName} has changed`); | ||
let success = true; | ||
map.forEach((contents: string, fileName: string) => { | ||
// This ensures that we delete any generated files from modules that have been deleted | ||
const allExistingFiles = globby.sync(`${outputDir}/**`); | ||
allExistingFiles.forEach(existingFile => { | ||
if (!map.has(path.normalize(existingFile))) { | ||
fs.unlinkSync(existingFile); | ||
} | ||
}); | ||
for (const [fileName, contents] of map) { | ||
try { | ||
const location = path.join(outputDir, fileName); | ||
fs.mkdirSync(path.dirname(location), {recursive: true}); | ||
fs.writeFileSync(location, contents); | ||
fs.mkdirSync(path.dirname(fileName), {recursive: true}); | ||
if (fs.existsSync(fileName)) { | ||
const currentContents = fs.readFileSync(fileName, 'utf8'); | ||
// Don't update the files if there are no changes as this breaks incremental builds | ||
if (currentContents === contents) { | ||
continue; | ||
} | ||
} | ||
fs.writeFileSync(fileName, contents); | ||
} catch (error) { | ||
success = false; | ||
console.error(`Failed to write ${fileName} to ${outputDir}`, error); | ||
console.error(`Failed to write ${fileName} to ${fileName}`, error); | ||
} | ||
}); | ||
} | ||
@@ -159,12 +198,9 @@ return success; | ||
const generatedModuleFiles = []; | ||
const generatedComponentFiles = []; | ||
/* | ||
for (const name of generators) { | ||
for (const generator of GENERATORS[name]) { | ||
generatedFiles.push(...generator(libraryName, schema, moduleSpecName)); | ||
} | ||
} | ||
*/ | ||
const generatedFiles = new Map<string, string>(); | ||
generatedFiles.set( | ||
path.join(outputDirectory, '.clang-format'), | ||
'DisableFormat: true\nSortIncludes: false', | ||
); | ||
const generateNM2 = createNM2Generator({namespace: argv.namespace}); | ||
@@ -184,33 +220,30 @@ const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH') | ||
generatedModuleFiles.push( | ||
...generateNM2(libraryName, schema, moduleSpecName), | ||
normalizeFileMap( | ||
generateNM2(libraryName, schema, moduleSpecName), | ||
outputDirectory, | ||
generatedFiles, | ||
); | ||
generatedComponentFiles.push( | ||
...generatorPropsH(libraryName, schema, moduleSpecName), | ||
...generatorPropsCPP(libraryName, schema, moduleSpecName), | ||
...generatorShadowNodeH(libraryName, schema, moduleSpecName), | ||
...generatorShadowNodeCPP(libraryName, schema, moduleSpecName), | ||
...generatorComponentDescriptorH(libraryName, schema, moduleSpecName), | ||
...generatorEventEmitterH(libraryName, schema, moduleSpecName), | ||
); | ||
const componentGenerators = [ | ||
generatorPropsH, | ||
generatorPropsCPP, | ||
generatorShadowNodeH, | ||
generatorShadowNodeCPP, | ||
generatorComponentDescriptorH, | ||
generatorEventEmitterH, | ||
]; | ||
const moduleFilesToUpdate = new Map<string, string>([ | ||
...generatedModuleFiles, | ||
]); | ||
const componentFilesToUpdate = new Map<string, string>([ | ||
...generatedComponentFiles, | ||
]); | ||
componentGenerators.forEach(generator => { | ||
normalizeFileMap( | ||
generator(libraryName, schema, moduleSpecName), | ||
componentOutputdir, | ||
generatedFiles, | ||
); | ||
}); | ||
if (test === true) { | ||
return ( | ||
checkFilesForChanges(moduleFilesToUpdate, outputDirectory) && | ||
checkFilesForChanges(componentFilesToUpdate, componentOutputdir) | ||
); | ||
return checkFilesForChanges(generatedFiles, outputDirectory); | ||
} | ||
return ( | ||
writeMapToFiles(moduleFilesToUpdate, outputDirectory) && | ||
writeMapToFiles(componentFilesToUpdate, componentOutputdir) | ||
); | ||
return writeMapToFiles(generatedFiles, outputDirectory); | ||
} | ||
@@ -217,0 +250,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45638
1193