Skip to content

Commit

Permalink
chore(deps): Modernize some dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Mar 24, 2024
1 parent dd3eca8 commit 2dd352e
Show file tree
Hide file tree
Showing 20 changed files with 1,261 additions and 4,150 deletions.
5,106 changes: 1,109 additions & 3,997 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
"elementtree": "^0.1.7",
"endent": "^2.1.0",
"fast-glob": "^3.2.12",
"fs-extra": "^11.1.0",
"glob": "^7.1.6",
"lodash.assign": "^4.2.0",
"lodash.isdate": "^4.0.1",
"lodash.isobject": "^3.0.2",
"lodash.zip": "^4.2.0",
"plist": "^3.0.6",
"q": "^1.5.1",
Expand All @@ -37,7 +32,6 @@
},
"devDependencies": {
"@cordova/eslint-config": "^5.0.0",
"@nodelib/fs.macchiato": "^1.0.4",
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
"nyc": "^15.1.0",
Expand Down
74 changes: 37 additions & 37 deletions spec/ConfigChanges/ConfigChanges.spec.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions spec/ConfigChanges/ConfigFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

const rewire = require('rewire');
const fs = require('fs-extra');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const readChunk = require('read-chunk');

describe('ConfigFile tests', function () {
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('ConfigFile tests', function () {
const expectedPlistPath = `${projName}${path.sep}${projName}-Info.plist`;

ConfigFile.__set__('getIOSProjectname', () => projName);
spyOn(require('glob'), 'sync').and.returnValue([
spyOn(require('fast-glob'), 'sync').and.returnValue([
`AAA/${projName}-Info.plist`,
`Pods/Target Support Files/Pods-${projName}/Info.plist`,
`Pods/Target Support Files/Pods-${projName}/Pods-${projName}-Info.plist`,
Expand Down
6 changes: 3 additions & 3 deletions spec/ConfigParser/ConfigParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
under the License.
*/

const path = require('path');
const fs = require('fs-extra');
const path = require('node:path');
const fs = require('node:fs');
const ConfigParser = require('../../src/ConfigParser/ConfigParser');
const xml = path.join(__dirname, '../fixtures/test-config.xml');
const xml_contents = fs.readFileSync(xml, 'utf-8');
const xml_contents = fs.readFileSync(xml, 'utf8');

describe('config.xml parser', function () {
beforeEach(function () {
Expand Down
56 changes: 30 additions & 26 deletions spec/CordovaCheck.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,79 @@
under the License.
*/

const fs = require('fs-extra');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const CordovaCheck = require('../src/CordovaCheck');

const cwd = process.cwd();
const home = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
const origPWD = process.env.PWD;
const testDirName = 'cordova-common-test-somedir';

function touchFile (filepath) {
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, '');
}

describe('findProjectRoot method', function () {
afterEach(function () {
process.env.PWD = origPWD;
process.chdir(cwd);

const somedir = path.join(home, testDirName);
fs.rmSync(somedir, { recursive: true, force: true });
});

it('Test 001 : should return false if it hits the home directory', function () {
const somedir = path.join(home, 'somedir');
fs.emptyDirSync(somedir);
const somedir = path.join(home, testDirName);
fs.mkdirSync(somedir, { recursive: true });
expect(CordovaCheck.findProjectRoot(somedir)).toEqual(false);
});
it('Test 002 : should return false if it cannot find a .cordova directory up the directory tree', function () {
const somedir = path.join(home, '..');
expect(CordovaCheck.findProjectRoot(somedir)).toEqual(false);
});
it('Test 003 : should return the first directory it finds with a .cordova folder in it', function () {
const somedir = path.join(home, 'somedir');
const somedir = path.join(home, testDirName);
const anotherdir = path.join(somedir, 'anotherdir');
fs.removeSync(somedir);
fs.ensureDirSync(anotherdir);
fs.ensureFileSync(path.join(somedir, 'www', 'config.xml'));
fs.mkdirSync(anotherdir, { recursive: true });
touchFile(path.join(somedir, 'www', 'config.xml'));
expect(CordovaCheck.findProjectRoot(somedir)).toEqual(somedir);
});
it('Test 004 : should ignore PWD when its undefined', function () {
delete process.env.PWD;
const somedir = path.join(home, 'somedir');
const somedir = path.join(home, testDirName);
const anotherdir = path.join(somedir, 'anotherdir');
fs.removeSync(somedir);
fs.ensureDirSync(anotherdir);
fs.ensureDirSync(path.join(somedir, 'www'));
fs.ensureFileSync(path.join(somedir, 'config.xml'));
fs.mkdirSync(anotherdir, { recursive: true });
fs.mkdirSync(path.join(somedir, 'www'), { recursive: true });
touchFile(path.join(somedir, 'config.xml'));
process.chdir(anotherdir);
expect(CordovaCheck.findProjectRoot()).toEqual(somedir);
});
it('Test 005 : should use PWD when available', function () {
const somedir = path.join(home, 'somedir');
const somedir = path.join(home, testDirName);
const anotherdir = path.join(somedir, 'anotherdir');
fs.removeSync(somedir);
fs.ensureDirSync(anotherdir);
fs.ensureFileSync(path.join(somedir, 'www', 'config.xml'));
fs.mkdirSync(anotherdir, { recursive: true });
touchFile(path.join(somedir, 'www', 'config.xml'));
process.env.PWD = anotherdir;
process.chdir(path.sep);
expect(CordovaCheck.findProjectRoot()).toEqual(somedir);
});
it('Test 006 : should use cwd as a fallback when PWD is not a cordova dir', function () {
const somedir = path.join(home, 'somedir');
const somedir = path.join(home, testDirName);
const anotherdir = path.join(somedir, 'anotherdir');
fs.removeSync(somedir);
fs.ensureDirSync(anotherdir);
fs.ensureFileSync(path.join(somedir, 'www', 'config.xml'));
fs.mkdirSync(anotherdir, { recursive: true });
touchFile(path.join(somedir, 'www', 'config.xml'));
process.env.PWD = path.sep;
process.chdir(anotherdir);
expect(CordovaCheck.findProjectRoot()).toEqual(somedir);
});
it('Test 007 : should ignore platform www/config.xml', function () {
const somedir = path.join(home, 'somedir');
const somedir = path.join(home, testDirName);
const anotherdir = path.join(somedir, 'anotherdir');
fs.removeSync(somedir);
fs.ensureFileSync(path.join(anotherdir, 'www', 'config.xml'));
fs.ensureDirSync(path.join(somedir, 'www'));
fs.ensureFileSync(path.join(somedir, 'config.xml'));
touchFile(path.join(anotherdir, 'www', 'config.xml'));
fs.mkdirSync(path.join(somedir, 'www'), { recursive: true });
touchFile(path.join(somedir, 'config.xml'));
expect(CordovaCheck.findProjectRoot(anotherdir)).toEqual(somedir);
});
});
28 changes: 9 additions & 19 deletions spec/FileUpdater.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
under the License.
*/

const path = require('path');
const { Stats } = require('node:fs');
const path = require('node:path');
const rewire = require('rewire');
const { Stats } = require('@nodelib/fs.macchiato');

const FileUpdater = rewire('../src/FileUpdater');

Expand All @@ -39,20 +39,10 @@ FileUpdater.__set__('updatePathWithStats', function () {

// Create mock fs.Stats to simulate file or directory attributes.
function mockFileStats (modified) {
return new Stats({
isFile: true,
isDirectory: false,
ctime: modified,
mtime: modified
});
return new Stats(0, 32768, 0, 0, 0, 0, 0, 0, 0, 0, null, modified, modified, null);
}
function mockDirStats () {
return new Stats({
isFile: false,
isDirectory: true,
ctime: null,
mtime: null
});
return new Stats(0, 16384, 0, 0, 0, 0, 0, 0, 0, 0, null, null, null, null);
}

class SystemError extends Error {
Expand All @@ -63,7 +53,7 @@ class SystemError extends Error {
}
}

// Create a mock to replace the fs-extra module used by the FileUpdater,
// Create a mock to replace the fs module used by the FileUpdater,
// so the tests don't have to actually touch the filesystem.
const mockFs = {
mkdirPaths: [],
Expand Down Expand Up @@ -100,15 +90,15 @@ const mockFs = {
return this.statSync(fileOrDirPath);
},

ensureDirSync: function (path) {
mkdirSync: function (path, opts) {
this.mkdirPaths.push(path);
},

copySync: function (sourcePath, targetPath) {
cpSync: function (sourcePath, targetPath, opts) {
this.cpPaths.push([sourcePath, targetPath]);
},

removeSync: function (path) {
rmSync: function (path, opts) {
this.rmPaths.push(path);
},

Expand All @@ -118,7 +108,7 @@ const mockFs = {
}
};

FileUpdater.__set__('fs', mockFs);
FileUpdater.__set__('node:fs', mockFs);

// Define some constants used in the test cases.
const testRootDir = 'testRootDir';
Expand Down
4 changes: 2 additions & 2 deletions spec/PlatformJson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
under the License.
*/

const fs = require('node:fs');
const rewire = require('rewire');
const PlatformJson = rewire('../src/PlatformJson');
const ModuleMetadata = PlatformJson.__get__('ModuleMetadata');
Expand Down Expand Up @@ -133,8 +134,7 @@ describe('PlatformJson class', function () {

describe('generateAndSaveMetadata method', function () {
it('should save generated metadata', function () {
// Needs to use graceful-fs, since that is used by fs-extra
const spy = spyOn(require('graceful-fs'), 'writeFileSync');
const spy = spyOn(fs, 'writeFileSync');

const dest = require('path').join(__dirname, 'test-destination');
platformJson.addPluginMetadata(fakePlugin).generateAndSaveMetadata(dest);
Expand Down
15 changes: 7 additions & 8 deletions spec/PluginManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
under the License.
*/

const fs = require('fs-extra');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const rewire = require('rewire');
const PluginInfo = require('../src/PluginInfo/PluginInfo');
const ConfigChanges = require('../src/ConfigChanges/ConfigChanges');
Expand All @@ -36,9 +36,8 @@ const FAKE_LOCATIONS = {
describe('PluginManager class', function () {
beforeEach(function () {
spyOn(ConfigChanges, 'PlatformMunger');
spyOn(fs, 'outputJsonSync');
spyOn(fs, 'writeFileSync');
spyOn(fs, 'ensureDirSync');
spyOn(fs, 'mkdirSync');
});

it('Test 001 : should be constructable', function () {
Expand Down Expand Up @@ -97,8 +96,8 @@ describe('PluginManager class', function () {

return manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})
.then(function () {
expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8');
expect(fs.writeFileSync).not.toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8');
expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf8');
expect(fs.writeFileSync).not.toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf8');
});
});

Expand All @@ -108,8 +107,8 @@ describe('PluginManager class', function () {

return manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), { usePlatformWww: true })
.then(function () {
expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8');
expect(fs.writeFileSync).toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8');
expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf8');
expect(fs.writeFileSync).toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf8');
});
});
});
Expand Down
23 changes: 15 additions & 8 deletions src/ConfigChanges/ConfigFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
*
*/

const fs = require('fs-extra');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const readChunk = require('read-chunk');

// Use delay loading to ensure plist and other node modules to not get loaded
// on Android, Windows platforms
const modules = {
get bplist () { return require('bplist-parser'); },
get et () { return require('elementtree'); },
get glob () { return require('glob'); },
get glob () { return require('fast-glob'); },
get plist () { return require('plist'); },
get plist_helpers () { return require('../util/plist-helpers'); },
get xml_helpers () { return require('../util/xml-helpers'); }
Expand Down Expand Up @@ -85,7 +85,7 @@ class ConfigFile {

save () {
if (this.type === 'xml') {
fs.writeFileSync(this.filepath, this.data.write({ indent: 4 }), 'utf-8');
fs.writeFileSync(this.filepath, this.data.write({ indent: 4 }), 'utf8');
} else {
// plist
const regExp = /<string>[ \t\r\n]+?<\/string>/g;
Expand Down Expand Up @@ -167,8 +167,11 @@ function resolveConfigFilePath (project_dir, platform, file) {

if (file.includes('*')) {
// handle wildcards in targets using glob.
matches = modules.glob.sync(path.join(project_dir, '**', file))
.map(p => path.normalize(p));
matches = modules.glob.sync(`**/${file}`, {
fs,
cwd: project_dir,
absolute: true
}).map(path.normalize);

if (matches.length) filepath = matches[0];

Expand Down Expand Up @@ -217,7 +220,11 @@ function resolveConfigFilePath (project_dir, platform, file) {
'config.xml'
);
} else {
matches = modules.glob.sync(path.join(project_dir, '**', 'config.xml'));
matches = modules.glob.sync('**/config.xml', {
fs,
cwd: project_dir,
absolute: true
}).map(path.normalize);
if (matches.length) filepath = matches[0];
}

Expand All @@ -231,7 +238,7 @@ function resolveConfigFilePath (project_dir, platform, file) {
// Find out the real name of an iOS or OSX project
// TODO: glob is slow, need a better way or caching, or avoid using more than once.
function getIOSProjectname (project_dir) {
const matches = modules.glob.sync('*.xcodeproj', { cwd: project_dir });
const matches = modules.glob.sync('*.xcodeproj', { cwd: project_dir, onlyDirectories: true });

if (matches.length !== 1) {
const msg = matches.length === 0
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigParser/ConfigParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const et = require('elementtree');
const { parseElementtreeSync } = require('../util/xml-helpers');
const CordovaError = require('../CordovaError');
const fs = require('fs-extra');
const fs = require('node:fs');
const events = require('../events');

const CDV_XMLNS_URI = 'http://cordova.apache.org/ns/1.0';
Expand Down Expand Up @@ -487,7 +487,7 @@ class ConfigParser {
}

write () {
fs.writeFileSync(this.path, this.doc.write({ indent: 4 }), 'utf-8');
fs.writeFileSync(this.path, this.doc.write({ indent: 4 }), 'utf8');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/CordovaCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
under the License.
*/

const fs = require('fs-extra');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');

function isRootDir (dir) {
if (fs.existsSync(path.join(dir, 'www'))) {
Expand Down
Loading

0 comments on commit 2dd352e

Please sign in to comment.