Skip to content

Commit

Permalink
chore(deps): Modernize some dependencies (#203)
Browse files Browse the repository at this point in the history
* chore(deps): Modernize some dependencies
* chore(ci): Test on Node 20
  • Loading branch information
dpogue authored Mar 27, 2024
1 parent 5fbb4be commit 12135bd
Show file tree
Hide file tree
Showing 26 changed files with 1,272 additions and 4,183 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -48,6 +48,6 @@ jobs:

- name: upload coverage
if: success()
uses: codecov/codecov-action@v3.1.1
uses: codecov/codecov-action@v3
with:
name: ${{ runner.os }} node.js ${{ matrix.node-version }}
5,128 changes: 1,109 additions & 4,019 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);
});
});
32 changes: 11 additions & 21 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 Expand Up @@ -286,7 +276,7 @@ describe('FileUpdater class', function () {
let loggedTarget = 0;
let loggedRoot = 0;
FileUpdater.updatePathWithStats(
testSourceDir, mockDirStats(now), testTargetDir, null, { rootDir: testRootDir },
testSourceDir, mockDirStats(), testTargetDir, null, { rootDir: testRootDir },
function (message) {
loggedSource += new RegExp(testSourceDir).test(message) ? 1 : 0;
loggedTarget += new RegExp(testTargetDir).test(message) ? 1 : 0;
Expand All @@ -302,7 +292,7 @@ describe('FileUpdater class', function () {
let loggedTarget = 0;
let loggedRoot = 0;
FileUpdater.updatePathWithStats(
testSourceDir, null, testTargetDir, mockDirStats(now), { rootDir: testRootDir },
testSourceDir, null, testTargetDir, mockDirStats(), { rootDir: testRootDir },
function (message) {
loggedSource += new RegExp(testSourceDir).test(message) ? 1 : 0;
loggedTarget += new RegExp(testTargetDir).test(message) ? 1 : 0;
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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./org.test.plugins.childbrowser/www/childbrowser.js
//org.test.plugins.childbrowser/www/childbrowser.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./org.test.plugins.dummyplugin/src/blackberry10/index.js
//org.test.plugins.dummyplugin/src/blackberry10/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./org.test.plugins.dummyplugin/src/tizen/dummer.js
//org.test.plugins.dummyplugin/src/tizen/dummer.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./org.test.plugins.dummyplugin/src/windows8/dummer.js
//org.test.plugins.dummyplugin/src/windows/dummer.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./org.test.plugins.dummyplugin/www/dummyplugin.js
//org.test.plugins.dummyplugin/www/dummyplugin.js
Loading

0 comments on commit 12135bd

Please sign in to comment.