chore(migrate): apps/* to webpack5 (#9606)

This commit is contained in:
Igor Randjelovic
2021-12-21 18:47:33 +01:00
committed by GitHub
parent 04c0f8783d
commit a88cacab89
62 changed files with 643 additions and 404 deletions

View File

@@ -137,7 +137,12 @@ exports[`angular configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -167,7 +172,12 @@ exports[`angular configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -259,7 +269,12 @@ exports[`angular configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -391,8 +406,8 @@ exports[`angular configuration for android 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -538,7 +553,12 @@ exports[`angular configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -568,7 +588,12 @@ exports[`angular configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -660,7 +685,12 @@ exports[`angular configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -792,8 +822,8 @@ exports[`angular configuration for ios 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [
@@ -806,7 +836,7 @@ exports[`angular configuration for ios 1`] = `
exports[`angular configuration loads polyfills.android.ts into the bundle entry if it exists 1`] = `
Array [
"__jest__/src/polyfills.android.ts",
"@nativescript/core/bundle-entry-points.js",
"@nativescript/core/bundle-entry-points",
"__jest__/src/app.js",
"@nativescript/core/ui/frame",
"@nativescript/core/ui/frame/activity",
@@ -816,7 +846,7 @@ Array [
exports[`angular configuration loads polyfills.ios.ts into the bundle entry if it exists 1`] = `
Array [
"__jest__/src/polyfills.ios.ts",
"@nativescript/core/bundle-entry-points.js",
"@nativescript/core/bundle-entry-points",
"__jest__/src/app.js",
]
`;
@@ -824,7 +854,7 @@ Array [
exports[`angular configuration loads polyfills.ts into the bundle entry if it exists 1`] = `
Array [
"__jest__/src/polyfills.ts",
"@nativescript/core/bundle-entry-points.js",
"@nativescript/core/bundle-entry-points",
"__jest__/src/app.js",
]
`;

View File

@@ -141,7 +141,12 @@ exports[`base configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -166,7 +171,12 @@ exports[`base configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -294,8 +304,8 @@ exports[`base configuration for android 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -445,7 +455,12 @@ exports[`base configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -470,7 +485,12 @@ exports[`base configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -598,8 +618,8 @@ exports[`base configuration for ios 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [

View File

@@ -141,7 +141,12 @@ exports[`javascript configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -166,7 +171,12 @@ exports[`javascript configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -302,9 +312,9 @@ exports[`javascript configuration for android 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/globals/index',
'__jest__/src/__@nativescript_webpack_virtual_entry_javascript__',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -454,7 +464,12 @@ exports[`javascript configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -479,7 +494,12 @@ exports[`javascript configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -615,9 +635,9 @@ exports[`javascript configuration for ios 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/globals/index',
'__jest__/src/__@nativescript_webpack_virtual_entry_javascript__',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [

View File

@@ -163,7 +163,12 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -188,7 +193,12 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -323,8 +333,8 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -478,7 +488,12 @@ exports[`react configuration > android > base config 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -503,7 +518,12 @@ exports[`react configuration > android > base config 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -627,8 +647,8 @@ exports[`react configuration > android > base config 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -800,7 +820,12 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -825,7 +850,12 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -960,8 +990,8 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [
@@ -1116,7 +1146,12 @@ exports[`react configuration > ios > base config 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -1141,7 +1176,12 @@ exports[`react configuration > ios > base config 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -1265,8 +1305,8 @@ exports[`react configuration > ios > base config 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [

View File

@@ -145,7 +145,12 @@ exports[`svelte configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -170,7 +175,12 @@ exports[`svelte configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -315,8 +325,8 @@ exports[`svelte configuration for android 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -470,7 +480,12 @@ exports[`svelte configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -495,7 +510,12 @@ exports[`svelte configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -640,8 +660,8 @@ exports[`svelte configuration for ios 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [

View File

@@ -141,7 +141,12 @@ exports[`typescript configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -166,7 +171,12 @@ exports[`typescript configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -302,9 +312,9 @@ exports[`typescript configuration for android 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/globals/index',
'__jest__/src/__@nativescript_webpack_virtual_entry_typescript__',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -454,7 +464,12 @@ exports[`typescript configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -479,7 +494,12 @@ exports[`typescript configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -615,9 +635,9 @@ exports[`typescript configuration for ios 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/globals/index',
'__jest__/src/__@nativescript_webpack_virtual_entry_typescript__',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [

View File

@@ -151,7 +151,12 @@ exports[`vue configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -180,7 +185,12 @@ exports[`vue configuration for android 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -328,8 +338,8 @@ exports[`vue configuration for android 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js',
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity'
@@ -489,7 +499,12 @@ exports[`vue configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -518,7 +533,12 @@ exports[`vue configuration for ios 1`] = `
options: {
postcssOptions: {
plugins: [
'postcss-import'
[
'postcss-import',
{
resolve: function () { /* omitted long function */ }
}
]
]
}
}
@@ -666,8 +686,8 @@ exports[`vue configuration for ios 1`] = `
],
entry: {
bundle: [
'@nativescript/core/globals/index.js',
'@nativescript/core/bundle-entry-points.js',
'@nativescript/core/globals/index',
'@nativescript/core/bundle-entry-points',
'__jest__/src/app.js'
],
'tns_modules/inspector_modules': [

View File

@@ -44,41 +44,43 @@ function getContext(
return {
rootContext: 'app',
context: 'app/component',
async: () => (error, source: string) => {
if (callbackCalled) {
done.fail('Callback called more than once!');
}
callbackCalled = true;
async() {
return (error, source: string) => {
if (callbackCalled) {
throw new Error('Callback called more than once!');
}
callbackCalled = true;
expectedDeps.forEach((expectedDep) => {
expect(actualDeps).toContain(expectedDep);
});
expectedDeps.forEach((expectedDep) => {
expect(actualDeps).toContain(expectedDep);
});
expectedRegs.forEach(({ name, path }) => {
expect(source).toContain(dedent`
expectedRegs.forEach(({ name, path }) => {
expect(source).toContain(dedent`
global.registerModule(
'${name}',
() => require("${path}")
)
`);
});
});
if (assureNoDeps) {
expect(actualDeps.length).toBe(0);
expect(source).not.toContain('global.registerModule');
}
if (assureNoDeps) {
expect(actualDeps.length).toBe(0);
expect(source).not.toContain('global.registerModule');
}
if (expectWarnings) {
expect(actualWarnings.length).toEqual(expectWarnings);
}
if (expectWarnings) {
expect(actualWarnings.length).toEqual(expectWarnings);
}
if (error && !expectError) {
done.fail(error);
} else if (!error && expectError) {
done.fail('Error expected here');
} else {
done();
}
if (error && !expectError) {
throw error;
} else if (!error && expectError) {
throw new Error('Error expected here');
} else {
done();
}
};
},
resolve: (
context: string,
@@ -272,10 +274,13 @@ describe('xml-namespace-loader', () => {
const expectedDeps = [];
const expectedRegs = [
{ name: 'nativescript-ui-chart', path: 'nativescript-ui-chart' },
{
name: 'nativescript-ui-chart',
path: 'node_modules/nativescript-ui-chart/ui-chart.js',
},
{
name: 'nativescript-ui-chart/RadCartesianChart',
path: 'nativescript-ui-chart',
path: 'node_modules/nativescript-ui-chart/ui-chart.js',
},
];
@@ -392,25 +397,16 @@ describe('xml-namespace-loader', () => {
});
it("with '&&', '||', '<=' and '>=' in binding expression, emits warnings, but does not fail", (done) => {
const resolveMap = {
'nativescript-ui-chart': 'node_modules/nativescript-ui-chart/ui-chart.js',
};
const resolveMap = {};
const expectedDeps = [];
const expectedRegs = [
{ name: 'nativescript-ui-chart', path: 'nativescript-ui-chart' },
{
name: 'nativescript-ui-chart/RadCartesianChart',
path: 'nativescript-ui-chart',
},
];
const expectedRegs = [];
const testXml = `
<Page xmlns="http://www.nativescript.org/tns.xsd">
<StackLayout xmlns:chart="nativescript-ui-chart">
<TextField text="{{ var1 && var2 || var1 >= var2 || var2 <= var1 }}" />
<chart:RadCartesianChart></chart:RadCartesianChart>
</StackLayout>
</Page>`;

View File

@@ -201,10 +201,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
// replace globals with the polyfills file which
// should handle loading the correct globals
// and any additional polyfills required.
if (paths.includes('@nativescript/core/globals/index.js')) {
paths[
paths.indexOf('@nativescript/core/globals/index.js')
] = polyfillsPath;
if (paths.includes('@nativescript/core/globals/index')) {
paths[paths.indexOf('@nativescript/core/globals/index')] = polyfillsPath;
// replace paths with the updated paths
config.entry('bundle').clear().merge(paths);

View File

@@ -1,10 +1,11 @@
import { extname, resolve } from 'path';
import {
ContextExclusionPlugin,
DefinePlugin,
HotModuleReplacementPlugin,
} from 'webpack';
import Config from 'webpack-chain';
import { resolve } from 'path';
import { existsSync } from 'fs';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
@@ -86,8 +87,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
config
.entry('bundle')
// ensure we load nativescript globals first
.add('@nativescript/core/globals/index.js')
.add('@nativescript/core/bundle-entry-points.js')
.add('@nativescript/core/globals/index')
.add('@nativescript/core/bundle-entry-points')
.add(entryPath);
// Add android app components to the bundle to SBG can generate the java classes
@@ -126,6 +127,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
config.optimization.minimizer('TerserPlugin').use(TerserPlugin, [
{
terserOptions: {
// @ts-ignore - https://github.com/webpack-contrib/terser-webpack-plugin/pull/463 broke the types?
compress: {
collapse_vars: platform !== 'android',
sequences: platform !== 'android',
@@ -276,7 +278,36 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
postcssOptions: {
plugins: [
// inlines @imported stylesheets
'postcss-import',
[
'postcss-import',
{
// custom resolver to resolve platform extensions in @import statements
// ie. @import "foo.css" would import "foo.ios.css" if the platform is ios and it exists
resolve(id, baseDir, importOptions) {
const ext = extname(id);
const platformExt = ext ? `.${platform}${ext}` : '';
if (!id.includes(platformExt)) {
const platformRequest = id.replace(ext, platformExt);
const extPath = resolve(baseDir, platformRequest);
try {
return require.resolve(platformRequest, {
paths: [baseDir],
});
} catch {}
if (existsSync(extPath)) {
console.log(`resolving "${id}" to "${platformRequest}"`);
return extPath;
}
}
// fallback to postcss-import default resolution
return id;
},
},
],
],
},
};

View File

@@ -30,7 +30,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
chainedSetAddAfter(
config.entry('bundle'),
'@nativescript/core/globals/index.js',
'@nativescript/core/globals/index',
virtualEntryPath
);

View File

@@ -30,7 +30,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
chainedSetAddAfter(
config.entry('bundle'),
'@nativescript/core/globals/index.js',
'@nativescript/core/globals/index',
virtualEntryPath
);

View File

@@ -78,6 +78,10 @@ async function parseXML(content: string): Promise<ParseResult> {
`${localModulePath}.xml`,
moduleName,
namespace,
`${moduleName}.xml`,
`~/${moduleName}`,
`~/${namespace}`,
`~/${moduleName}.xml`,
];
DEBUG && console.log({ resolvePaths });
let resolvedPath;
@@ -118,12 +122,13 @@ async function parseXML(content: string): Promise<ParseResult> {
this.addDependency(xml);
namespaces.push({ name: `${moduleName}.xml`, path: xml });
})
.catch(() => {
// if there is no XML file, fall back to namespace as the path
// will become require(<namespace>)
namespaces.push({ name: namespace, path: namespace });
namespaces.push({ name: moduleName, path: namespace });
});
.catch(noop);
// .catch(() => {
// // if there is no XML file, fall back to namespace as the path
// // will become require(<namespace>)
// namespaces.push({ name: namespace, path: namespace });
// namespaces.push({ name: moduleName, path: namespace });
// });
// look for css files with the same name
await resolveAsync(this.context, `${noExtFilename}.css`)
@@ -163,6 +168,8 @@ async function parseXML(content: string): Promise<ParseResult> {
distinctNamespaces.set(name, path.replace(/\\/g, '/'));
});
DEBUG && console.log({ distinctNamespaces });
distinctNamespaces.forEach((path, name) => {
moduleRegisters.push(dedent`
global.registerModule(