Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-27480_1
Browse files Browse the repository at this point in the history
  • Loading branch information
ssekhri committed Nov 12, 2019
2 parents 96b8823 + ab5df03 commit 7fd8fea
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashMap;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
Expand Down Expand Up @@ -55,6 +56,11 @@ private void fireItemClick(String event, Object data)
TiViewProxy source = (TiViewProxy) eventData.get(TiC.EVENT_PROPERTY_SOURCE);
if (source != null && !source.equals(this) && listProxy != null) {

// FIXME: We should not need to create a placeholder proxy for each item. ListView needs refactoring to remedy this.
source = (TiViewProxy) KrollProxy.createProxy(source.getClass(), source.getKrollObject(), new Object[0],
source.getCreationUrl().url);
eventData.put(TiC.EVENT_PROPERTY_SOURCE, source);

// append bind properties
if (eventData.containsKey(TiC.PROPERTY_BIND_ID) && eventData.containsKey(TiC.PROPERTY_ITEM_INDEX)
&& eventData.containsKey(TiC.PROPERTY_SECTION)) {
Expand Down
24 changes: 9 additions & 15 deletions build/lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const commonjs = require('rollup-plugin-commonjs');

const git = require('./git');
const utils = require('./utils');
const copyPackageAndDependencies = utils.copyPackageAndDependencies;
const Packager = require('./packager');

const ROOT_DIR = path.join(__dirname, '..', '..');
Expand Down Expand Up @@ -38,9 +37,7 @@ function determineBabelOptions(babelOptions) {
const options = {
...babelOptions,
useBuiltIns: 'entry',
// DO NOT include web polyfills!
exclude: [ 'web.dom.iterable', 'web.immediate', 'web.timers' ],
corejs: 2
corejs: 3
};

return {
Expand Down Expand Up @@ -103,8 +100,8 @@ class Builder {
this.program.gitHash = hash || 'n/a';
}

async transpile(platform, babelOptions) {
// Copy over common dir, @babel/polyfill, etc into some temp dir
async transpile(platform, babelOptions, outFile) {
// Copy over common dir, into some temp dir
// Then run rollup/babel on it, then just copy the resulting bundle to our real destination!
// The temporary location we'll assembled the transpiled bundle
const TMP_COMMON_DIR = path.join(TMP_DIR, '_common');
Expand All @@ -113,13 +110,6 @@ class Builder {
console.log(`Creating temporary 'common' directory...`); // eslint-disable-line quotes
await fs.copy(path.join(ROOT_DIR, 'common'), TMP_COMMON_PLAFORM_DIR);

// copy over polyfill and its dependencies
console.log('Copying polyfills...');
const modulesDir = path.join(TMP_COMMON_PLAFORM_DIR, 'Resources/node_modules');
// make sure our 'node_modules' directory exists
await fs.ensureDir(modulesDir);
copyPackageAndDependencies('@babel/polyfill', modulesDir);

// create a bundle
console.log('Transpile and run rollup...');
const bundle = await rollup({
Expand All @@ -132,8 +122,12 @@ class Builder {
external: [ './app', 'com.appcelerator.aca' ]
});

console.log(`Writing 'common' bundle...`); // eslint-disable-line quotes
await bundle.write({ format: 'cjs', file: path.join(TMP_DIR, 'common', platform, 'ti.main.js') });
if (!outFile) {
outFile = path.join(TMP_DIR, 'common', platform, 'ti.main.js');
}

console.log(`Writing 'common' bundle to ${outFile} ...`); // eslint-disable-line quotes
await bundle.write({ format: 'cjs', file: outFile });

// We used to have to copy over ti.internal, but it is now bundled into ti.main.js
// if we ever have files there that cannot be bundled or are not hooked up properly, we'll need to copy them here manually.
Expand Down
52 changes: 0 additions & 52 deletions build/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,56 +305,4 @@ Utils.installSDK = async function (versionTag, symlinkIfPossible = false) {
});
};

/**
* Given an npm module id, this will copy it and it's dependencies to a
* destination "node_modules" folder.
* Note that all of the packages are copied to the top-level of "node_modules",
* not nested!
* Also, to shortcut the logic, if the original package has been copied to the
* destination we will *not* attempt to read it's dependencies and ensure those
* are copied as well! So if the modules version changes or something goes
* haywire and the copies aren't full finished due to a failure, the only way to
* get right is to clean the destination "node_modules" dir before rebuilding.
*
* @param {String} moduleId The npm package/module to copy (along with it's dependencies)
* @param {String} destNodeModulesDir path to the destination "node_modules" folder
* @param {Array} [paths=[]] Array of additional paths to pass to require.resolve() (in addition to those from require.resolve.paths(moduleId))
*/
function copyPackageAndDependencies(moduleId, destNodeModulesDir, paths = []) {
const destPackage = path.join(destNodeModulesDir, moduleId);
if (fs.existsSync(path.join(destPackage, 'package.json'))) {
return; // if the module seems to exist in the destination, just skip it.
}

// copy the dependency's folder over
let pkgJSONPath;
if (require.resolve.paths) {
const thePaths = require.resolve.paths(moduleId);
pkgJSONPath = require.resolve(path.join(moduleId, 'package.json'), { paths: thePaths.concat(paths) });
} else {
pkgJSONPath = require.resolve(path.join(moduleId, 'package.json'));
}
const srcPackage = path.dirname(pkgJSONPath);
const srcPackageNodeModulesDir = path.join(srcPackage, 'node_modules');
for (let i = 0; i < 3; i++) {
fs.copySync(srcPackage, destPackage, {
preserveTimestamps: true,
filter: src => !src.startsWith(srcPackageNodeModulesDir)
});

// Quickly verify package copied, I've experienced occurences where it does not.
// Retry up to three times if it did not copy correctly.
if (fs.existsSync(path.join(destPackage, 'package.json'))) {
break;
}
}

// Now read it's dependencies and recurse on them
const packageJSON = fs.readJSONSync(pkgJSONPath);
for (const dependency in packageJSON.dependencies) {
copyPackageAndDependencies(dependency, destNodeModulesDir, [ srcPackageNodeModulesDir ]);
}
}
Utils.copyPackageAndDependencies = copyPackageAndDependencies;

module.exports = Utils;
61 changes: 7 additions & 54 deletions build/scons-xcode-project-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ const util = require('util');
const exec = util.promisify(require('child_process').exec); // eslint-disable-line security/detect-child-process
const fs = require('fs-extra');
const path = require('path');
const copyPackageAndDependencies = require('./lib/utils').copyPackageAndDependencies;
const rollup = require('rollup').rollup;
const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const IOS = require('./lib/ios');
const Builder = require('./lib/builder');

program.parse(process.argv);

Expand All @@ -19,7 +16,6 @@ const targetBuildDir = program.args[1];
const productName = program.args[2];

const ROOT_DIR = path.join(__dirname, '..');
const commonSDKJS = path.join(ROOT_DIR, 'common/Resources');
const appDir = path.join(targetBuildDir, `${productName}.app`);
const xcodeProjectResources = path.join(projectDir, '../Resources');
const localeCompiler = path.join(ROOT_DIR, 'support/dev/localecompiler.py');
Expand Down Expand Up @@ -49,59 +45,16 @@ async function generateIndexJSON(dirToTraverse) {
return fs.writeFile(destFile, JSON.stringify(index));
}

function determineBabelOptions() {
// eslint-disable-next-line security/detect-non-literal-require
const { minIosVersion } = require(path.join(ROOT_DIR, 'iphone/package.json'));
const options = {
targets: {
ios: minIosVersion
},
useBuiltIns: 'entry',
// DO NOT include web polyfills!
exclude: [ 'web.dom.iterable', 'web.immediate', 'web.timers' ]
};
return {
presets: [ [ '@babel/env', options ] ],
exclude: 'node_modules/**'
};
}
async function generateBundle(outputDir) {
const builder = new Builder({ args: [ 'ios' ] });
const ios = new IOS({ });

async function copyPolyfills(dir) {
console.log('Copying JS polyfills over');
const modulesDir = path.join(dir, 'node_modules');
// make sure our 'node_modules' destination directory exists
await fs.emptyDir(modulesDir);
copyPackageAndDependencies('@babel/polyfill', modulesDir);
await builder.transpile('ios', ios.babelOptions, path.join(outputDir, 'ti.main.js'));
}

async function generateBundle(inputDir, outputDir) {
console.log('Transpiling and bundling common SDK JS');

// create a bundle
console.log('running rollup');
const babelOptions = determineBabelOptions();
const bundle = await rollup({
input: `${inputDir}/ti.main.js`,
plugins: [
resolve(),
commonjs({
ignore: [ '/semantic.colors.json' ]
}),
babel(babelOptions)
],
external: [ './app', 'com.appcelerator.aca', '/semantic.colors.json' ]
});

// write the bundle to disk
console.log('Writing common SDK JS bundle to disk');
return bundle.write({ format: 'cjs', file: `${outputDir}/ti.main.js` });
}
// FIXME: Combine common code here and in packager.js!
async function main(tmpBundleDir) {
await fs.emptyDir(tmpBundleDir);
await fs.copy(commonSDKJS, tmpBundleDir); // copy our common SDK JS files to tmp location
await copyPolyfills(tmpBundleDir); // copy @babel/polyfill there too
await generateBundle(tmpBundleDir, appDir); // run rollup/babel to generate single bundled ti.main.js in app
await generateBundle(appDir); // run rollup/babel to generate single bundled ti.main.js in app
console.log(`Removing temp dir used for bundling: ${tmpBundleDir}`);
await fs.remove(tmpBundleDir); // remove tmp location
console.log(`Copying xcode resources: ${xcodeProjectResources} -> ${appDir}`);
Expand Down
4 changes: 3 additions & 1 deletion common/Resources/ti.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ try {
}

// Load JS language polyfills
import '@babel/polyfill';
import 'core-js/es';
// Load polyfill for async/await usage
import 'regenerator-runtime/runtime';
// import all of our polyfills/extensions
import './ti.internal/extensions';

Expand Down
26 changes: 23 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"commander": "^3.0.1",
"commitizen": "^4.0.3",
"conventional-changelog-cli": "^2.0.25",
"core-js": "^2.6.5",
"core-js": "^3.3.2",
"cz-conventional-changelog": "^3.0.2",
"danger": "^9.2.4",
"dateformat": "^3.0.3",
Expand Down

0 comments on commit 7fd8fea

Please sign in to comment.