Skip to content

Commit 1fbb7a4

Browse files
authored
chore(dependency-profiles): make profile updater more dynamic (#3895)
1 parent ff2088a commit 1fbb7a4

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "Made profile updater more dynamic",
4+
"packageName": "@fluentui-react-native/dependency-profiles",
5+
"email": "[email protected]",
6+
"dependentChangeType": "none"
7+
}

packages/dependency-profiles/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"scripts": {
1616
"build": "fluentui-scripts build",
17-
"update-profile": "node update-profile.js"
17+
"update-profile": "node update-profile.mjs"
1818
},
1919
"devDependencies": {
2020
"@fluentui-react-native/adapters": "*",

packages/dependency-profiles/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by 'update-profile.js'
1+
// This file was generated by 'update-profile.mjs'
22
/* eslint-disable */
33
module.exports = {
44
"0.73": {

packages/dependency-profiles/update-profile.js renamed to packages/dependency-profiles/update-profile.mjs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// @ts-check
2+
import * as path from 'node:path';
3+
import * as fs from 'node:fs';
4+
import { URL, fileURLToPath } from 'node:url';
5+
import semverCoerce from 'semver/functions/coerce.js';
6+
import { getAllPackageJsonFiles } from 'workspace-tools';
27

3-
const path = require('path');
4-
5-
const OUTPUT_FILE = `${__dirname}/src/index.js`;
8+
const OUTPUT_FILE = fileURLToPath(new URL("src/index.js", import.meta.url));
69

710
const CAPABILITY_MAP = {
811
// empty for now
912
};
1013

11-
const fs = require('fs');
12-
const semver = require('semver');
13-
const { getAllPackageJsonFiles } = require('workspace-tools');
14-
const { name: thisPackageName, devDependencies } = require('./package.json');
15-
1614
/**
1715
* Returns the contents of the file at specified path.
1816
* @param {string} path
@@ -22,6 +20,8 @@ function readFile(path) {
2220
return fs.readFileSync(path, { encoding: 'utf-8' });
2321
}
2422

23+
const { name: thisPackageName, devDependencies } = JSON.parse(readFile('./package.json'));
24+
2525
const packages = {};
2626

2727
// Look for react-native capabilities
@@ -31,10 +31,10 @@ for (const [name, capability] of Object.entries(CAPABILITY_MAP)) {
3131
}
3232
}
3333

34-
const workspacePackages = getAllPackageJsonFiles(__dirname);
35-
for (const manifestPath of workspacePackages.sort()) {
36-
const { name, version, private, devOnly } = JSON.parse(readFile(manifestPath));
37-
if (private || name === thisPackageName || name === '@fluentui-react-native/codemods') {
34+
const workspacePackages = getAllPackageJsonFiles(OUTPUT_FILE)?.sort() ?? [];
35+
for (const manifestPath of workspacePackages) {
36+
const { name, version, private: isPrivate, devOnly } = JSON.parse(readFile(manifestPath));
37+
if (isPrivate || name === thisPackageName || name === '@fluentui-react-native/codemods') {
3838
continue;
3939
}
4040

@@ -48,22 +48,25 @@ for (const manifestPath of workspacePackages.sort()) {
4848
packages[name] = { name, version, devOnly };
4949
}
5050

51-
const { major, minor } = semver.coerce(devDependencies['react-native']);
52-
53-
let profiles;
51+
const { major, minor } = semverCoerce(devDependencies['react-native']) ?? {};
5452

5553
// When updating FURN to a new react-native version, save the profile for
5654
// the current react-native version in index.js to a new file under src named
5755
// "furn-profile-X.Y.js" and add that profile here. For example:
58-
//
59-
profiles = {
60-
[`${major}.${minor}`]: packages,
61-
...require('./src/furn-profile-0.72.js'),
62-
...require('./src/furn-profile-0.71.js'),
63-
};
56+
const profiles = { [`${major}.${minor}`]: packages };
57+
for (const filename of fs.readdirSync("./src").sort().reverse()) {
58+
if (!filename.startsWith("furn-profile-")) {
59+
continue;
60+
}
61+
62+
const { default: profile } = await import(`./src/${filename}`);
63+
for (const [key, value] of Object.entries(profile)) {
64+
profiles[key] = value;
65+
}
66+
}
6467

6568
const source = [
66-
`// This file was generated by '${path.basename(__filename)}'`,
69+
`// This file was generated by '${path.basename(import.meta.url)}'`,
6770
'/* eslint-disable */',
6871
`module.exports = ${JSON.stringify(profiles, undefined, 2)};`,
6972
'',

0 commit comments

Comments
 (0)