Skip to content

Commit

Permalink
refactor!: do not copy JS lib to platform project (#1203)
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael von der Grün <[email protected]>
erisu and raphinesse authored Dec 1, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 457bfa0 commit 07383c1
Showing 38 changed files with 745 additions and 724 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bin/node_modules/*
templates/project/*
tests/spec/unit/fixtures/*

686 changes: 1 addition & 685 deletions bin/templates/scripts/cordova/Api.js

Large diffs are not rendered by default.

704 changes: 704 additions & 0 deletions lib/Api.js

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 2 additions & 7 deletions bin/lib/create.js → lib/create.js
Original file line number Diff line number Diff line change
@@ -21,9 +21,9 @@ const path = require('path');
const fs = require('fs-extra');
const xmlescape = require('xml-escape');
const { CordovaError, events } = require('cordova-common');
const pkg = require('../../package');
const pkg = require('../package');

const ROOT = path.join(__dirname, '../..');
const ROOT = path.join(__dirname, '..');

/**
* Creates a new iOS project with the following options:
@@ -101,11 +101,6 @@ class ProjectCreator {
const srcScriptsDir = path.join(ROOT, 'bin/templates/scripts/cordova');
const destScriptsDir = this.projectPath('cordova');
fs.copySync(srcScriptsDir, destScriptsDir);

const nodeModulesDir = path.join(ROOT, 'node_modules');
if (fs.existsSync(nodeModulesDir)) {
fs.copySync(nodeModulesDir, path.join(destScriptsDir, 'node_modules'));
}
}

expandTokens () {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "cordova-ios",
"version": "7.0.0-dev",
"description": "cordova-ios release",
"main": "bin/templates/scripts/cordova/Api.js",
"main": "lib/Api.js",
"repository": "github:apache/cordova-ios",
"bugs": "https://github.com/apache/cordova-ios/issues",
"keywords": [
@@ -54,7 +54,7 @@
},
"nyc": {
"include": [
"bin/templates/scripts/**"
"lib/**"
],
"reporter": [
"lcov",
9 changes: 8 additions & 1 deletion tests/spec/create.spec.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const xcode = require('xcode');
const create = require('../../bin/lib/create');
const create = require('../../lib/create');

const makeTempDir = () => path.join(
fs.realpathSync(os.tmpdir()),
@@ -64,6 +64,13 @@ function verifyProjectBundleIdentifier (tmpDir, projectName, expectedBundleIdent
* @returns {Promise}
*/
function verifyBuild (tmpDir) {
// Allow test project to find the `cordova-ios` module
fs.ensureSymlinkSync(
path.join(__dirname, '../..'),
path.join(tmpDir, 'node_modules/cordova-ios'),
'junction'
);

const Api = require(path.join(tmpDir, 'cordova/Api.js'));

return expectAsync(new Api('ios', tmpDir).build({ emulator: true }))
14 changes: 7 additions & 7 deletions tests/spec/unit/Api.spec.js
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ const path = require('path');
const fs = require('fs-extra');
const EventEmitter = require('events');
const PluginManager = require('cordova-common').PluginManager;
const Api = require('../../../bin/templates/scripts/cordova/Api');
const check_reqs = require('../../../bin/templates/scripts/cordova/lib/check_reqs');
const Api = require('../../../lib/Api');
const check_reqs = require('../../../lib/check_reqs');

// The lib/run module pulls in ios-sim, which has a hard requirement that it
// be run on a Mac OS - simply requiring the module is enough to trigger the
@@ -31,13 +31,13 @@ const check_reqs = require('../../../bin/templates/scripts/cordova/lib/check_req
// method (more below).
let run_mod;
if (process.platform === 'darwin') {
run_mod = require('../../../bin/templates/scripts/cordova/lib/run');
run_mod = require('../../../lib/run');
}

const projectFile = require('../../../bin/templates/scripts/cordova/lib/projectFile');
const BridgingHeader_mod = require('../../../bin/templates/scripts/cordova/lib/BridgingHeader.js');
const Podfile_mod = require('../../../bin/templates/scripts/cordova/lib/Podfile');
const PodsJson_mod = require('../../../bin/templates/scripts/cordova/lib/PodsJson');
const projectFile = require('../../../lib/projectFile');
const BridgingHeader_mod = require('../../../lib/BridgingHeader.js');
const Podfile_mod = require('../../../lib/Podfile');
const PodsJson_mod = require('../../../lib/PodsJson');
const FIXTURES = path.join(__dirname, 'fixtures');
const iosProjectFixture = path.join(FIXTURES, 'ios-config-xml');

2 changes: 1 addition & 1 deletion tests/spec/unit/BridgingHeader.spec.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
const fs = require('fs-extra');
const path = require('path');

const BridgingHeader = require(path.resolve(path.join(__dirname, '..', '..', '..', 'bin', 'templates', 'scripts', 'cordova', 'lib', 'BridgingHeader.js'))).BridgingHeader;
const BridgingHeader = require(path.resolve(path.join(__dirname, '../../../lib/BridgingHeader.js'))).BridgingHeader;
const fixtureBridgingHeader = fs.readFileSync(path.resolve(__dirname, 'fixtures', 'test-Bridging-Header.h'), 'utf-8');

describe('unit tests for BridgingHeader module', () => {
2 changes: 1 addition & 1 deletion tests/spec/unit/Plugman/common.spec.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ const path = require('path');
const osenv = require('os');
const rewire = require('rewire');

const common = rewire('../../../../bin/templates/scripts/cordova/lib/plugman/pluginHandlers');
const common = rewire('../../../../lib/plugman/pluginHandlers');

const test_dir = path.join(osenv.tmpdir(), 'test_plugman');
const project_dir = path.join(test_dir, 'project');
6 changes: 3 additions & 3 deletions tests/spec/unit/Plugman/pluginHandler.spec.js
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@ const rewire = require('rewire');
const EventEmitter = require('events');

const PluginInfo = require('cordova-common').PluginInfo;
const Api = require('../../../../bin/templates/scripts/cordova/Api');
const projectFile = require('../../../../bin/templates/scripts/cordova/lib/projectFile');
const pluginHandlers = rewire('../../../../bin/templates/scripts/cordova/lib/plugman/pluginHandlers');
const Api = require('../../../../lib/Api');
const projectFile = require('../../../../lib/projectFile');
const pluginHandlers = rewire('../../../../lib/plugman/pluginHandlers');

const temp = path.join(os.tmpdir(), 'plugman');

2 changes: 1 addition & 1 deletion tests/spec/unit/Podfile.spec.js
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ const fs = require('fs-extra');
const CordovaError = require('cordova-common').CordovaError;

const PROJECT_NAME = 'testProj';
const Podfile = require(path.resolve(path.join(__dirname, '..', '..', '..', 'bin', 'templates', 'scripts', 'cordova', 'lib', 'Podfile.js'))).Podfile;
const Podfile = require(path.resolve(path.join(__dirname, '../../../lib/Podfile.js'))).Podfile;
const fixturePodfile = path.resolve(__dirname, 'fixtures', PROJECT_NAME, 'platforms', 'ios', 'Podfile');
const fixturePodXcconfigDebug = path.resolve(__dirname, 'fixtures', PROJECT_NAME, 'platforms', 'ios', 'pods-debug.xcconfig');
const fixturePodXcconfigRelease = path.resolve(__dirname, 'fixtures', PROJECT_NAME, 'platforms', 'ios', 'pods-release.xcconfig');
2 changes: 1 addition & 1 deletion tests/spec/unit/PodsJson.spec.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const path = require('path');
const util = require('util');
const CordovaError = require('cordova-common').CordovaError;

const PodsJson = require(path.resolve(path.join(__dirname, '..', '..', '..', 'bin', 'templates', 'scripts', 'cordova', 'lib', 'PodsJson.js'))).PodsJson;
const PodsJson = require(path.resolve(path.join(__dirname, '../../../lib/PodsJson.js'))).PodsJson;
const fixturePodsJson = path.resolve(__dirname, 'fixtures', 'testProj', 'platforms', 'ios', 'pods.json');

// tests are nested in a describe to ensure clean up happens after all unit tests are run
4 changes: 2 additions & 2 deletions tests/spec/unit/build.spec.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ const path = require('path');
const fs = require('fs-extra');
const rewire = require('rewire');
const { CordovaError, events } = require('cordova-common');
const build = rewire('../../../bin/templates/scripts/cordova/lib/build');
const build = rewire('../../../lib/build');

describe('build', () => {
const testProjectPath = path.join('/test', 'project', 'path');
@@ -385,7 +385,7 @@ describe('build', () => {

beforeEach(() => {
// rewire causes some issues so for these tests, we will require instead.
buildRequire = require('../../../bin/templates/scripts/cordova/lib/build');
buildRequire = require('../../../lib/build');
spyOn(events, 'emit');
});

4 changes: 2 additions & 2 deletions tests/spec/unit/lib/check_reqs.spec.js
Original file line number Diff line number Diff line change
@@ -19,12 +19,12 @@

const rewire = require('rewire');
const which = require('which');
const versions = require('../../../../bin/templates/scripts/cordova/lib/versions');
const versions = require('../../../../lib/versions');

describe('check_reqs', () => {
let checkReqs;
beforeEach(() => {
checkReqs = rewire('../../../../bin/templates/scripts/cordova/lib/check_reqs');
checkReqs = rewire('../../../../lib/check_reqs');
});

describe('checkTool method', () => {
2 changes: 1 addition & 1 deletion tests/spec/unit/lib/list-devices.spec.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ const fs = require('fs-extra');
const path = require('path');
const rewire = require('rewire');

const list_devices = rewire('../../../../bin/templates/scripts/cordova/lib/listDevices');
const list_devices = rewire('../../../../lib/listDevices');

const sampleData = fs.readFileSync(path.resolve(__dirname, '../fixtures/sample-ioreg-output.txt'), 'utf-8');

2 changes: 1 addition & 1 deletion tests/spec/unit/lib/list-emulator-images.spec.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
// allow for interacting with iOS Simulators. On Windows+Linux we are
// bound to not-have-that.
if (process.platform === 'darwin') {
const list_emus = require('../../../../bin/templates/scripts/cordova/lib/listEmulatorImages');
const list_emus = require('../../../../lib/listEmulatorImages');
const iossim = require('ios-sim');

describe('cordova/lib/listEmulatorImages', () => {
2 changes: 1 addition & 1 deletion tests/spec/unit/lib/run.spec.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
// environment bits that allow for interacting with iOS Simulators. On
// Windows+Linux we are bound to not-have-that.
if (process.platform === 'darwin') {
const run = require('../../../../bin/templates/scripts/cordova/lib/run');
const run = require('../../../../lib/run');

describe('cordova/lib/run', () => {
describe('--list option', () => {
2 changes: 1 addition & 1 deletion tests/spec/unit/pluginAdd.spec.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const fs = require('fs-extra');
const EventEmitter = require('events').EventEmitter;
const ConfigParser = require('cordova-common').ConfigParser;
const PluginInfo = require('cordova-common').PluginInfo;
const Api = require('../../../bin/templates/scripts/cordova/Api');
const Api = require('../../../lib/Api');

const FIXTURES = path.join(__dirname, 'fixtures');
const DUMMY_PLUGIN = 'org.test.plugins.dummyplugin';
6 changes: 3 additions & 3 deletions tests/spec/unit/prepare.spec.js
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ const path = require('path');
const plist = require('plist');
const xcode = require('xcode');
const rewire = require('rewire');
const prepare = rewire('../../../bin/templates/scripts/cordova/lib/prepare');
const projectFile = require('../../../bin/templates/scripts/cordova/lib/projectFile');
const prepare = rewire('../../../lib/prepare');
const projectFile = require('../../../lib/projectFile');
const FileUpdater = require('cordova-common').FileUpdater;

const tmpDir = path.join(__dirname, '../../../tmp');
@@ -42,7 +42,7 @@ describe('prepare', () => {
let p;
let Api;
beforeEach(() => {
Api = rewire('../../../bin/templates/scripts/cordova/Api');
Api = rewire('../../../lib/Api');

fs.ensureDirSync(iosPlatform);
fs.copySync(iosProjectFixture, iosPlatform);
2 changes: 1 addition & 1 deletion tests/spec/unit/preparePlatform.spec.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const fs = require('fs-extra');
const EventEmitter = require('events').EventEmitter;
const ConfigParser = require('cordova-common').ConfigParser;
const PluginInfo = require('cordova-common').PluginInfo;
const Api = require('../../../bin/templates/scripts/cordova/Api');
const Api = require('../../../lib/Api');

const FIXTURES = path.join(__dirname, 'fixtures');
const DUMMY_PLUGIN = 'org.test.plugins.dummyplugin';
2 changes: 1 addition & 1 deletion tests/spec/unit/projectFile.spec.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const projectFile = require('../../../bin/templates/scripts/cordova/lib/projectFile');
const projectFile = require('../../../lib/projectFile');

const iosProject = path.join(os.tmpdir(), 'plugman/projectFile');
const iosProjectFixture = path.join(__dirname, 'fixtures/ios-config-xml');
2 changes: 1 addition & 1 deletion tests/spec/unit/versions.spec.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/

const semver = require('semver');
const versions = require('../../../bin/templates/scripts/cordova/lib/versions');
const versions = require('../../../lib/versions');

// These tests can not run on windows.
if (process.platform === 'darwin') {

0 comments on commit 07383c1

Please sign in to comment.