Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 33c2134

Browse files
committed
feat: remove webpack compiler logic
1 parent 6f73bb8 commit 33c2134

11 files changed

+35
-347
lines changed

Diff for: lib/after-prepare.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ const { installSnapshotArtefacts } = require("../snapshot/android/project-snapsh
22
const { shouldSnapshot } = require("./utils");
33

44
module.exports = function (hookArgs) {
5-
const env = hookArgs.env || {};
6-
env.hmr = hookArgs.appFilesUpdaterOptions.useHotModuleReload;
5+
const env = hookArgs.prepareData.env || {};
76
const shouldSnapshotOptions = {
8-
platform: hookArgs.platform,
9-
bundle: hookArgs.appFilesUpdaterOptions.bundle,
10-
release: hookArgs.appFilesUpdaterOptions.release
7+
platform: hookArgs.prepareData.platform,
8+
release: hookArgs.prepareData.release
119
};
1210

1311
if (env.snapshot && shouldSnapshot(shouldSnapshotOptions)) {
14-
installSnapshotArtefacts(hookArgs.projectData.projectDir);
12+
installSnapshotArtefacts(hookArgs.prepareData.projectDir);
1513
}
1614
}

Diff for: lib/before-cleanApp.js

-16
This file was deleted.

Diff for: lib/before-watchPatterns.js

-19
This file was deleted.

Diff for: lib/compiler.js

-182
This file was deleted.

Diff for: lib/utils.js

+2-94
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,18 @@
11
const os = require("os");
2-
3-
const {
4-
getAppPathFromProjectData,
5-
getAppResourcesPathFromProjectData,
6-
isAndroid,
7-
} = require("../projectHelpers");
8-
9-
const eventHandlers = {};
10-
11-
function debuggingEnabled(liveSyncService, projectDir) {
12-
const deviceDescriptors = liveSyncService.getLiveSyncDeviceDescriptors(projectDir);
13-
return deviceDescriptors.some(device => device.debugggingEnabled);
14-
}
15-
16-
function buildEnvData($projectData, platform, env) {
17-
const envData = Object.assign({},
18-
env,
19-
{ [platform.toLowerCase()]: true }
20-
);
21-
22-
const appPath = getAppPathFromProjectData($projectData);
23-
const appResourcesPath = getAppResourcesPathFromProjectData($projectData);
24-
Object.assign(envData,
25-
appPath && { appPath },
26-
appResourcesPath && { appResourcesPath }
27-
);
28-
29-
return envData;
30-
}
31-
32-
/**
33-
* Checks if there's a file in the following pattern 5e0326f3bb50f9f26cf0.hot-update.json
34-
* if yes this is a HMR update and remove all bundle files as we don't need them to be synced,
35-
* but only the update chunks
36-
*/
37-
function getUpdatedEmittedFiles(emittedFiles, webpackRuntimeFiles) {
38-
let fallbackFiles = [];
39-
let hotHash;
40-
if (emittedFiles.some(x => x.endsWith('.hot-update.json'))) {
41-
let result = emittedFiles.slice();
42-
const hotUpdateScripts = emittedFiles.filter(x => x.endsWith('.hot-update.js'));
43-
hotUpdateScripts.forEach(hotUpdateScript => {
44-
const { name, hash } = parseHotUpdateChunkName(hotUpdateScript);
45-
hotHash = hash;
46-
// remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
47-
result = result.filter(file => file !== `${name}.js`);
48-
if (webpackRuntimeFiles && webpackRuntimeFiles.length) {
49-
// remove files containing only the Webpack runtime (e.g. runtime.js)
50-
result = result.filter(file => webpackRuntimeFiles.indexOf(file) === -1);
51-
}
52-
});
53-
//if applying of hot update fails, we must fallback to the full files
54-
fallbackFiles = emittedFiles.filter(file => result.indexOf(file) === -1);
55-
return { emittedFiles: result, fallbackFiles, hash: hotHash };
56-
}
57-
else {
58-
return { emittedFiles, fallbackFiles };
59-
}
60-
}
61-
62-
/**
63-
* Parse the filename of the hot update chunk.
64-
* @param name bundle.deccb264c01d6d42416c.hot-update.js
65-
* @returns { name: string, hash: string } { name: 'bundle', hash: 'deccb264c01d6d42416c' }
66-
*/
67-
function parseHotUpdateChunkName(name) {
68-
const matcher = /^(.+)\.(.+)\.hot-update/gm;
69-
const matches = matcher.exec(name);
70-
return {
71-
name: matches[1] || "",
72-
hash: matches[2] || "",
73-
};
74-
}
2+
const { isAndroid } = require("../projectHelpers");
753

764
function shouldSnapshot(config) {
775
const platformSupportsSnapshot = isAndroid(config.platform);
786
const osSupportsSnapshot = os.type() !== "Windows_NT";
797

80-
return config.bundle && config.release && platformSupportsSnapshot && osSupportsSnapshot;
81-
}
82-
83-
function addListener(eventEmitter, name, handler) {
84-
if (!eventHandlers[name]) {
85-
eventEmitter.on(name, handler);
86-
eventHandlers[name] = handler;
87-
}
88-
}
89-
90-
function removeListener(eventEmitter, name) {
91-
if (eventHandlers[name]) {
92-
eventEmitter.removeListener(name, eventHandlers[name]);
93-
delete eventHandlers[name];
94-
}
8+
return config.release && platformSupportsSnapshot && osSupportsSnapshot;
959
}
9610

9711
function convertToUnixPath(relativePath) {
9812
return relativePath.replace(/\\/g, "/");
9913
}
10014

10115
module.exports = {
102-
buildEnvData,
103-
debuggingEnabled,
10416
shouldSnapshot,
105-
getUpdatedEmittedFiles,
106-
parseHotUpdateChunkName,
107-
addListener,
108-
removeListener,
10917
convertToUnixPath
11018
};

Diff for: package.json

+1-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
],
1111
"nativescript": {
1212
"hooks": [
13-
{
14-
"type": "before-cleanApp",
15-
"script": "lib/before-cleanApp.js",
16-
"inject": true
17-
},
18-
{
19-
"type": "before-watchPatterns",
20-
"script": "lib/before-watchPatterns.js",
21-
"inject": true
22-
},
2313
{
2414
"type": "after-prepare",
2515
"script": "lib/after-prepare.js",
@@ -35,7 +25,7 @@
3525
"scripts": {
3626
"postinstall": "node postinstall.js",
3727
"postpack": "rm -rf node_modules",
38-
"prepare": "tsc",
28+
"prepare": "tsc && npm run jasmine",
3929
"test": "npm run prepare && npm run jasmine",
4030
"jasmine": "jasmine --config=jasmine-config/jasmine.json",
4131
"version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"

0 commit comments

Comments
 (0)