Skip to content

Commit

Permalink
feat!: drop support for Node 14
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Dropped support for Node 14
  • Loading branch information
tido64 committed Oct 17, 2023
1 parent 15646f6 commit a7d56f0
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("node:path");

const exclusionList = (() => {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"typescript": "^5.0.0"
},
"engines": {
"node": ">=14.15"
"node": ">=16.13"
},
"packageManager": "[email protected]",
"resolutions": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/apply-config-plugins.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
// @ts-check

import * as fs from "fs/promises";
import * as path from "path";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { findFile } from "./validate-manifest.js";

async function main(projectRoot = process.cwd()) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/config-plugins/apply.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
import * as fs from "fs/promises";
import * as fs from "node:fs/promises";
import { withPlugins } from "./ExpoConfigPlugins.mjs";
import { compileModsAsync } from "./plugins/mod-compiler.mjs";
import { withInternal } from "./plugins/withInternal.mjs";
Expand Down
4 changes: 2 additions & 2 deletions scripts/config-plugins/plugins/withIosBaseMods.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { createRequire } from "module";
import * as path from "path";
import { createRequire } from "node:module";
import * as path from "node:path";
import { BaseMods } from "../ExpoConfigPlugins.mjs";
import { makeFilePathModifier, makeNullProvider } from "../provider.mjs";

Expand Down
2 changes: 1 addition & 1 deletion scripts/config-plugins/provider.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
import * as path from "path";
import * as path from "node:path";
import { findFile } from "../validate-manifest.js";
import { BaseMods } from "./ExpoConfigPlugins.mjs";

Expand Down
20 changes: 12 additions & 8 deletions scripts/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
require("./link")(module);

const chalk = require("chalk");
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const semver = require("semver");
const { parseArgs } = require("../scripts/parseargs");
const {
Expand Down Expand Up @@ -396,7 +396,7 @@ function reactNativeConfig({ name, testAppPath, platforms, flatten }) {
case "windows":
return join(
"const project = (() => {",
' const path = require("path");',
' const path = require("node:path");',
' const sourceDir = "windows";',
" try {",
' const { windowsProjectPath } = require("react-native-test-app");',
Expand Down Expand Up @@ -791,7 +791,7 @@ function gatherConfig(params, disableCache = false) {
* @param {string} packagePath
* @returns {string}
*/
function getAppName(packagePath, fs = require("fs")) {
function getAppName(packagePath, fs = require("node:fs")) {
try {
const { name } = readJSONFile(path.join(packagePath, "app.json"), fs);
if (typeof name === "string" && name) {
Expand All @@ -811,7 +811,11 @@ function getAppName(packagePath, fs = require("fs")) {
* @param {Configuration} config
* @returns {boolean}
*/
function isDestructive(packagePath, { files, oldFiles }, fs = require("fs")) {
function isDestructive(
packagePath,
{ files, oldFiles },
fs = require("node:fs")
) {
const modified = Object.keys(files).reduce((result, file) => {
const targetPath = path.join(packagePath, file);
if (fs.existsSync(targetPath)) {
Expand Down Expand Up @@ -849,7 +853,7 @@ function isDestructive(packagePath, { files, oldFiles }, fs = require("fs")) {
* @param {string} destination
* @returns {Promise<void[]>}
*/
function removeAllFiles(files, destination, fs = require("fs/promises")) {
function removeAllFiles(files, destination, fs = require("node:fs/promises")) {
const options = { force: true, maxRetries: 3, recursive: true };
return Promise.all(
files.map((filename) => fs.rm(path.join(destination, filename), options))
Expand All @@ -865,7 +869,7 @@ function removeAllFiles(files, destination, fs = require("fs/promises")) {
function updatePackageManifest(
path,
{ dependencies, scripts },
fs = require("fs")
fs = require("node:fs")
) {
const manifest = readJSONFile(path, fs);

Expand Down Expand Up @@ -894,7 +898,7 @@ function updatePackageManifest(
* @param {string} destination
* @returns {Promise<void[]>}
*/
function writeAllFiles(files, destination, fs = require("fs/promises")) {
function writeAllFiles(files, destination, fs = require("node:fs/promises")) {
const options = { recursive: true, mode: 0o755 };
return Promise.all(
Object.keys(files).map(async (filename) => {
Expand Down
8 changes: 4 additions & 4 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
"use strict";

const path = require("path");
const path = require("node:path");

/**
* Finds nearest relative path to a file or directory from current path.
Expand All @@ -12,7 +12,7 @@ const path = require("path");
function findNearest(
fileOrDirName,
currentDir = path.resolve(""),
fs = require("fs")
fs = require("node:fs")
) {
const rootDirectory =
process.platform === "win32"
Expand All @@ -37,7 +37,7 @@ function findNearest(
* @param {import("node:fs").PathLike} path
* @returns {T}
*/
function readJSONFile(path, fs = require("fs")) {
function readJSONFile(path, fs = require("node:fs")) {
return JSON.parse(fs.readFileSync(path, { encoding: "utf-8" }));
}

Expand All @@ -49,7 +49,7 @@ function readJSONFile(path, fs = require("fs")) {
function getPackageVersion(
module,
startDir = process.cwd(),
fs = require("fs")
fs = require("node:fs")
) {
const options = { paths: [startDir] };
const manifestPath = require.resolve(`${module}/package.json`, options);
Expand Down
8 changes: 4 additions & 4 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @ts-check
"use strict";

const { spawnSync } = require("child_process");
const path = require("path");
const { spawnSync } = require("node:child_process");
const path = require("node:path");

/**
* @template T
Expand Down Expand Up @@ -173,8 +173,8 @@ function getTemplate(platforms) {

require("https")
.get(url, (res) => {
const fs = require("fs");
const os = require("os");
const fs = require("node:fs");
const os = require("node:os");

const tmpDir = path.join(os.tmpdir(), "react-native-test-app");
fs.mkdirSync(tmpDir, { recursive: true });
Expand Down
2 changes: 1 addition & 1 deletion scripts/link.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

const path = require("path");
const path = require("node:path");

const localNodeModulesPath = path.join(process.cwd(), "node_modules");

Expand Down
2 changes: 1 addition & 1 deletion scripts/parseargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function formatHelp(description, options) {
);
}

const script = require("path").basename(process.argv[1]);
const script = require("node:path").basename(process.argv[1]);
return [
`usage: ${script} [options]`,
"",
Expand Down
2 changes: 1 addition & 1 deletion scripts/patch-cli-platform-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @ts-check
"use strict";

const fs = require("fs");
const fs = require("path:fs");

const nativeModulesScript = "native_modules.gradle";

Expand Down
8 changes: 4 additions & 4 deletions scripts/validate-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @ts-check
"use strict";

const path = require("path");
const path = require("node:path");
const { readJSONFile } = require("./helpers");
const { generateSchema } = require("./schema");

Expand All @@ -25,7 +25,7 @@ const BUILD_PROPS = [
* @param {string=} startDir
* @returns {string | undefined}
*/
function findFile(file, startDir = process.cwd(), fs = require("fs")) {
function findFile(file, startDir = process.cwd(), fs = require("node:fs")) {
let currentDir = startDir;
let candidate = path.join(currentDir, file);
while (!fs.existsSync(candidate)) {
Expand Down Expand Up @@ -53,7 +53,7 @@ function makeValidator() {
* @param {import("node:fs").PathLike | undefined} manifestPath
* @returns {Record<string, unknown> | number}
*/
function validateManifest(manifestPath, fs = require("fs")) {
function validateManifest(manifestPath, fs = require("node:fs")) {
if (!manifestPath) {
console.error(
`Failed to find '${APP_JSON}'. Please make sure you're in the right directory.`
Expand Down Expand Up @@ -92,7 +92,7 @@ function validateManifest(manifestPath, fs = require("fs")) {
function validate(
outputMode = "stdout",
projectRoot = process.cwd(),
fs = require("fs")
fs = require("node:fs")
) {
const manifestPath = findFile(APP_JSON, projectRoot, fs);
const manifest = validateManifest(manifestPath, fs);
Expand Down
24 changes: 12 additions & 12 deletions windows/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// @ts-check
"use strict";

const fs = require("fs");
const os = require("os");
const path = require("path");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const {
findNearest,
getPackageVersion,
Expand Down Expand Up @@ -65,7 +65,7 @@ const textFileWriteOptions = { encoding: "utf-8", mode: 0o644 };
* @param {string} src
* @param {string} dest
*/
function copy(src, dest, fs = require("fs")) {
function copy(src, dest, fs = require("node:fs")) {
fs.mkdir(dest, mkdirRecursiveOptions, (err) => {
rethrow(err);
fs.readdir(src, { withFileTypes: true }, (err, files) => {
Expand Down Expand Up @@ -312,7 +312,7 @@ function generateContentItems(
assets = { assetFilters: [], assetItemFilters: [], assetItems: [] },
currentFilter = "Assets",
source = "",
fs = require("fs")
fs = require("node:fs")
) {
const uuidv5 = (() => {
try {
Expand Down Expand Up @@ -396,7 +396,7 @@ function generateContentItems(
* @param {string} projectPath
* @returns {Assets}
*/
function parseResources(resources, projectPath, fs = require("fs")) {
function parseResources(resources, projectPath, fs = require("node:fs")) {
if (!Array.isArray(resources)) {
if (resources && resources.windows) {
return parseResources(resources.windows, projectPath, fs);
Expand Down Expand Up @@ -487,7 +487,7 @@ function copyAndReplace(
destPath,
replacements,
callback = rethrow,
fs = require("fs")
fs = require("node:fs")
) {
const stat = fs.statSync(srcPath);
if (stat.isDirectory()) {
Expand Down Expand Up @@ -528,7 +528,7 @@ function copyAndReplace(
* singleApp?: string;
* }} Application name, and paths to directories and files to include.
*/
function getBundleResources(manifestFilePath, fs = require("fs")) {
function getBundleResources(manifestFilePath, fs = require("node:fs")) {
// Default value if manifest or 'name' field don't exist.
const defaultName = "ReactTestApp";

Expand Down Expand Up @@ -581,7 +581,7 @@ function getBundleResources(manifestFilePath, fs = require("fs")) {
* @param {string} rnwPath Path to `react-native-windows`.
* @returns {string | null}
*/
function getHermesVersion(rnwPath, fs = require("fs")) {
function getHermesVersion(rnwPath, fs = require("node:fs")) {
const jsEnginePropsPath = path.join(
rnwPath,
"PropertySheets",
Expand All @@ -601,7 +601,7 @@ function getHermesVersion(rnwPath, fs = require("fs")) {
function generateSolution(
destPath,
{ autolink, useHermes, useNuGet },
fs = require("fs")
fs = require("node:fs")
) {
if (!destPath) {
return "Missing or invalid destination path";
Expand Down Expand Up @@ -913,7 +913,7 @@ function generateSolution(

if (autolink) {
Promise.all([...copyTasks, solutionTask]).then(() => {
const { spawn } = require("child_process");
const { spawn } = require("node:child_process");
spawn(
path.join(path.dirname(process.argv0), "npx.cmd"),
["react-native", "autolink-windows", "--proj", reactTestAppProjectPath],
Expand Down Expand Up @@ -956,7 +956,7 @@ if (require.main === module) {
autolink: {
description: `Run autolink after generating the solution (this is the default on Windows)`,
type: "boolean",
default: require("os").platform() === "win32",
default: require("node:os").platform() === "win32",
},
"use-hermes": {
description: "Use Hermes JavaScript engine (experimental)",
Expand Down

0 comments on commit a7d56f0

Please sign in to comment.