Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Made profile updater more dynamic",
"packageName": "@fluentui-react-native/dependency-profiles",
"email": "[email protected]",
"dependentChangeType": "none"
}
2 changes: 1 addition & 1 deletion packages/dependency-profiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"scripts": {
"build": "fluentui-scripts build",
"update-profile": "node update-profile.js"
"update-profile": "node update-profile.mjs"
},
"devDependencies": {
"@fluentui-react-native/adapters": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/dependency-profiles/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated by 'update-profile.js'
// This file was generated by 'update-profile.mjs'
/* eslint-disable */
module.exports = {
"0.73": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// @ts-check
import * as path from 'node:path';
import * as fs from 'node:fs';
import { URL, fileURLToPath } from 'node:url';
import semverCoerce from 'semver/functions/coerce.js';
import { getAllPackageJsonFiles } from 'workspace-tools';

const path = require('path');

const OUTPUT_FILE = `${__dirname}/src/index.js`;
const OUTPUT_FILE = fileURLToPath(new URL("src/index.js", import.meta.url));

const CAPABILITY_MAP = {
// empty for now
};

const fs = require('fs');
const semver = require('semver');
const { getAllPackageJsonFiles } = require('workspace-tools');
const { name: thisPackageName, devDependencies } = require('./package.json');

/**
* Returns the contents of the file at specified path.
* @param {string} path
Expand All @@ -22,6 +20,8 @@ function readFile(path) {
return fs.readFileSync(path, { encoding: 'utf-8' });
}

const { name: thisPackageName, devDependencies } = JSON.parse(readFile('./package.json'));

const packages = {};

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

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

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

const { major, minor } = semver.coerce(devDependencies['react-native']);

let profiles;
const { major, minor } = semverCoerce(devDependencies['react-native']) ?? {};

// When updating FURN to a new react-native version, save the profile for
// the current react-native version in index.js to a new file under src named
// "furn-profile-X.Y.js" and add that profile here. For example:
//
profiles = {
[`${major}.${minor}`]: packages,
...require('./src/furn-profile-0.72.js'),
...require('./src/furn-profile-0.71.js'),
};
const profiles = { [`${major}.${minor}`]: packages };
for (const filename of fs.readdirSync("./src").sort().reverse()) {
if (!filename.startsWith("furn-profile-")) {
continue;
}

const { default: profile } = await import(`./src/${filename}`);
for (const [key, value] of Object.entries(profile)) {
profiles[key] = value;
}
}

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