Merge branch 'master' into feat/node-fs

This commit is contained in:
Nathan Walker
2022-03-06 11:37:18 -08:00
committed by GitHub
23 changed files with 316 additions and 50 deletions

View File

@@ -147,7 +147,7 @@ export interface NativeScriptConfig {
*/
id?: string;
/**
* App's main entry file (currently ignored - set it in package.json main field)
* App's main entry file - this setting overrides the value set in package.json
*/
main?: string;
/**

View File

@@ -3,7 +3,7 @@ import { isCssVariable } from '../../core/properties';
import { isNullOrUndefined } from '../../../utils/types';
import * as cssParser from '../../../css';
import * as parser from '../../../css/parser';
import { Combinator as ICombinator , SimpleSelectorSequence as ISimpleSelectorSequence, Selector as ISelector, SimpleSelector as ISimpleSelector, parseSelector} from '../../../css/parser';
/**
* An interface describing the shape of a type on which the selectors may apply.
@@ -527,7 +527,7 @@ function createDeclaration(decl: cssParser.Declaration): any {
return { property: isCssVariable(decl.property) ? decl.property : decl.property.toLowerCase(), value: decl.value };
}
function createSimpleSelectorFromAst(ast: parser.SimpleSelector): SimpleSelector {
function createSimpleSelectorFromAst(ast: ISimpleSelector): SimpleSelector {
if (ast.type === '.') {
return new ClassSelector(ast.identifier);
}
@@ -553,7 +553,7 @@ function createSimpleSelectorFromAst(ast: parser.SimpleSelector): SimpleSelector
}
}
function createSimpleSelectorSequenceFromAst(ast: parser.SimpleSelectorSequence): SimpleSelectorSequence | SimpleSelector {
function createSimpleSelectorSequenceFromAst(ast: ISimpleSelectorSequence): SimpleSelectorSequence | SimpleSelector {
if (ast.length === 0) {
return new InvalidSelector(new Error('Empty simple selector sequence.'));
} else if (ast.length === 1) {
@@ -563,7 +563,7 @@ function createSimpleSelectorSequenceFromAst(ast: parser.SimpleSelectorSequence)
}
}
function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSelectorSequence | Selector {
function createSelectorFromAst(ast: ISelector): SimpleSelector | SimpleSelectorSequence | Selector {
if (ast.length === 0) {
return new InvalidSelector(new Error('Empty selector.'));
} else if (ast.length === 1) {
@@ -571,10 +571,10 @@ function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSel
} else {
const simpleSelectorSequences = [];
let simpleSelectorSequence: SimpleSelectorSequence | SimpleSelector;
let combinator: parser.Combinator;
let combinator: ICombinator;
for (let i = 0; i < ast.length; i++) {
simpleSelectorSequence = createSimpleSelectorSequenceFromAst(<parser.SimpleSelectorSequence>ast[i][0]);
combinator = <parser.Combinator>ast[i][1];
simpleSelectorSequence = createSimpleSelectorSequenceFromAst(<ISimpleSelectorSequence>ast[i][0]);
combinator = <ICombinator>ast[i][1];
if (combinator) {
simpleSelectorSequence.combinator = combinator;
}
@@ -587,7 +587,7 @@ function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSel
export function createSelector(sel: string): SimpleSelector | SimpleSelectorSequence | Selector {
try {
const parsedSelector = parser.parseSelector(sel);
const parsedSelector = parseSelector(sel);
if (!parsedSelector) {
return new InvalidSelector(new Error('Empty selector'));
}

View File

@@ -1,7 +1,7 @@
import { CoreTypes } from '../../core-types';
import { Color } from '../../color';
import { ColorStop } from './gradient';
import { LinearGradient as CSSLinearGradient } from '../../css/parser';
import type { LinearGradient as CSSLinearGradient } from '../../css/parser';
export class LinearGradient {
public angle: number;

View File

@@ -14,7 +14,7 @@ import { decompose2DTransformMatrix, getTransformMatrix, matrixArrayToCssMatrix,
import { Trace } from '../../trace';
import { CoreTypes } from '../../core-types';
import * as parser from '../../css/parser';
import { parseBackground } from '../../css/parser';
import { LinearGradient } from './linear-gradient';
import { CSSShadow, parseCSSShadow } from './css-shadow';
@@ -785,7 +785,7 @@ export const backgroundImageProperty = new CssProperty<Style, string | LinearGra
},
valueConverter: (value: any) => {
if (typeof value === 'string') {
const parsed = parser.parseBackground(value);
const parsed = parseBackground(value);
if (parsed) {
value = typeof parsed.value.image === 'object' ? LinearGradient.parse(parsed.value.image) : value;
}
@@ -837,7 +837,7 @@ backgroundPositionProperty.register(Style);
function convertToBackgrounds(this: void, value: string): [CssProperty<any, any>, any][] {
if (typeof value === 'string') {
const backgrounds = parser.parseBackground(value).value;
const backgrounds = parseBackground(value).value;
let backgroundColor = unsetValue;
if (backgrounds.color) {
backgroundColor = backgrounds.color instanceof Color ? backgrounds.color : new Color(backgrounds.color);

View File

@@ -6,11 +6,11 @@
module.exports = function (source, map) {
this.cacheable();
// Strips occurences of `moduleId: module.id,`, since it is no longer needed for webpack builds
// Strips occurrences of `moduleId: module.id,`, since it is no longer needed for webpack builds
const noModuleIdsSource = source.replace(/moduleId\:\s*module\.id\s*(\,)?/g, result =>
// Try to preserve char count so sourcemaps may remain intact
"/*" + result.substring(2, result.length - 2) + "*/"
);
this.callback(null, noModuleIdsSource, map);
};
};

View File

@@ -48,6 +48,8 @@ exports[`angular configuration for android 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -89,7 +91,7 @@ exports[`angular configuration for android 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -331,6 +333,10 @@ exports[`angular configuration for android 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -465,6 +471,8 @@ exports[`angular configuration for ios 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -506,7 +514,7 @@ exports[`angular configuration for ios 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -748,6 +756,10 @@ exports[`angular configuration for ios 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{

View File

@@ -40,6 +40,8 @@ exports[`base configuration for android 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -77,7 +79,7 @@ exports[`base configuration for android 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -242,6 +244,10 @@ exports[`base configuration for android 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -354,6 +360,8 @@ exports[`base configuration for ios 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -391,7 +399,7 @@ exports[`base configuration for ios 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -556,6 +564,10 @@ exports[`base configuration for ios 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -628,3 +640,9 @@ exports[`base configuration for ios 1`] = `
}
}"
`;
exports[`base configuration support env.watchNodeModules 1`] = `
Object {
"managedPaths": Array [],
}
`;

View File

@@ -40,6 +40,8 @@ exports[`javascript configuration for android 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -77,7 +79,7 @@ exports[`javascript configuration for android 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -242,6 +244,10 @@ exports[`javascript configuration for android 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -363,6 +369,8 @@ exports[`javascript configuration for ios 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -400,7 +408,7 @@ exports[`javascript configuration for ios 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -565,6 +573,10 @@ exports[`javascript configuration for ios 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{

View File

@@ -43,6 +43,8 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -87,7 +89,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -264,6 +266,10 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -386,6 +392,8 @@ exports[`react configuration > android > base config 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -423,7 +431,7 @@ exports[`react configuration > android > base config 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -589,6 +597,10 @@ exports[`react configuration > android > base config 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -700,6 +712,8 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -744,7 +758,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -921,6 +935,10 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -1044,6 +1062,8 @@ exports[`react configuration > ios > base config 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -1081,7 +1101,7 @@ exports[`react configuration > ios > base config 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -1247,6 +1267,10 @@ exports[`react configuration > ios > base config 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{

View File

@@ -44,6 +44,8 @@ exports[`svelte configuration for android 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -269,6 +271,10 @@ exports[`svelte configuration for android 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -379,6 +385,8 @@ exports[`svelte configuration for ios 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -604,6 +612,10 @@ exports[`svelte configuration for ios 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{

View File

@@ -40,6 +40,8 @@ exports[`typescript configuration for android 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -77,7 +79,7 @@ exports[`typescript configuration for android 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -242,6 +244,10 @@ exports[`typescript configuration for android 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -363,6 +369,8 @@ exports[`typescript configuration for ios 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -400,7 +408,7 @@ exports[`typescript configuration for ios 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -565,6 +573,10 @@ exports[`typescript configuration for ios 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{

View File

@@ -43,6 +43,8 @@ exports[`vue configuration for android 1`] = `
'.ts',
'.android.js',
'.js',
'.android.mjs',
'.mjs',
'.android.css',
'.css',
'.android.scss',
@@ -80,7 +82,7 @@ exports[`vue configuration for android 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -282,6 +284,10 @@ exports[`vue configuration for android 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(ios)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{
@@ -391,6 +397,8 @@ exports[`vue configuration for ios 1`] = `
'.ts',
'.ios.js',
'.js',
'.ios.mjs',
'.mjs',
'.ios.css',
'.css',
'.ios.scss',
@@ -428,7 +436,7 @@ exports[`vue configuration for ios 1`] = `
},
/* config.module.rule('workers') */
{
test: /\\\\.(js|ts)$/,
test: /\\\\.(mjs|js|ts)$/,
use: [
/* config.module.rule('workers').use('nativescript-worker-loader') */
{
@@ -630,6 +638,10 @@ exports[`vue configuration for ios 1`] = `
new ContextExclusionPlugin(
/(.*)App_Resources(.*)/
),
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
new ContextExclusionPlugin(
/\\\\.(android)\\\\.(\\\\w+)$/
),
/* config.plugin('DefinePlugin') */
new DefinePlugin(
{

View File

@@ -22,6 +22,14 @@ describe('base configuration', () => {
});
}
it('support env.watchNodeModules', () => {
init({
ios: true,
watchNodeModules: true,
});
expect(base(new Config()).get('snapshot')).toMatchSnapshot();
});
it('supports dotenv', () => {
const fsSpy = jest.spyOn(fs, 'existsSync');
fsSpy.mockReturnValue(true);
@@ -101,4 +109,14 @@ describe('base configuration', () => {
force: true,
});
});
it('supports --env.profile', () => {
init({
platform: 'ios',
profile: true,
});
const config = base(new Config());
expect(config.get('profile')).toBe(true);
});
});

View File

@@ -0,0 +1,49 @@
import { env } from '../../src/';
import { addPlatform, getEntryPath } from '../../src/helpers/platform';
import { getValue } from '../../src/helpers/config';
describe('getEntryPath', () => {
it('uses platform getEntryPath if the platform specifies it', () => {
env.platform = 'testPlatform';
addPlatform('testPlatform', {
getEntryPath() {
return 'custom-entry-path';
},
});
const res = getEntryPath();
expect(res).toEqual('custom-entry-path');
// cleanup env
delete env.platform;
});
it('uses main from nativescript.config.ts if set', () => {
env.ios = true;
// mock getValue
const getValueMock = getValue as jest.Mock;
const getValueMockImpl = getValueMock.getMockImplementation();
getValueMock.mockImplementation((key) => {
if (key === 'main') {
return 'main-from-config';
}
});
const res = getEntryPath();
expect(res).toEqual('__jest__/main-from-config');
// reset mock implementation
getValueMock.mockImplementation(getValueMockImpl);
});
it('uses main from package.json', () => {
env.ios = true;
const res = getEntryPath();
// set in jest.setup.ts mock for package.json...
expect(res).toEqual('__jest__/src/app.js');
});
});

View File

@@ -1,6 +1,6 @@
{
"name": "@nativescript/webpack",
"version": "5.0.4",
"version": "5.0.5-rc.0",
"private": false,
"main": "dist/index.js",
"files": [

View File

@@ -13,10 +13,10 @@ jest.mock('cosmiconfig', () => ({
},
}));
const getValueMock = jest.fn();
getValueMock.mockImplementation((key, defaultValue) => defaultValue);
jest.mock('../src/helpers/config.ts', () => ({
getValue(key, defaultValue) {
return defaultValue;
},
getValue: getValueMock,
}));
jest.mock('os', () => {

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { redBright, green, greenBright } from 'chalk';
import { redBright, green, greenBright, yellow } from 'chalk';
import { program } from 'commander';
import dedent from 'ts-dedent';
import webpack from 'webpack';
@@ -115,6 +115,28 @@ program
errorDetails: env.verbose,
})
);
// if webpack profile is enabled we write the stats to a JSON file
if (configuration.profile || env.profile) {
console.log(
[
'',
'|',
`| The build profile has been written to ${yellow(
'webpack.stats.json'
)}`,
`| You can analyse the stats at ${green(
'https://webpack.github.io/analyse/'
)}`,
'|',
'',
].join('\n')
);
fs.writeFileSync(
path.join(process.cwd(), 'webpack.stats.json'),
JSON.stringify(stats.toJson())
);
}
}
};

View File

@@ -22,8 +22,9 @@ import { env as _env, IWebpackEnv } from '../index';
import { getValue } from '../helpers/config';
import { getIPS } from '../helpers/host';
import {
getPlatformName,
getAvailablePlatforms,
getAbsoluteDistPath,
getPlatformName,
getEntryDirPath,
getEntryPath,
} from '../helpers/platform';
@@ -123,6 +124,13 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
],
});
// allow watching node_modules
config.when(env.watchNodeModules, (config) => {
config.set('snapshot', {
managedPaths: [],
});
});
// Set up Terser options
config.optimization.minimizer('TerserPlugin').use(TerserPlugin, [
{
@@ -172,6 +180,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
.add('.ts')
.add(`.${platform}.js`)
.add('.js')
.add(`.${platform}.mjs`)
.add('.mjs')
.add(`.${platform}.css`)
.add('.css')
.add(`.${platform}.scss`)
@@ -212,10 +222,15 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
});
});
// enable profiling with --env.profile
config.when(env.profile, (config) => {
config.profile(true);
});
// worker-loader should be declared before ts-loader
config.module
.rule('workers')
.test(/\.(js|ts)$/)
.test(/\.(mjs|js|ts)$/)
.use('nativescript-worker-loader')
.loader('nativescript-worker-loader');
@@ -365,6 +380,18 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
.plugin('ContextExclusionPlugin|App_Resources')
.use(ContextExclusionPlugin, [new RegExp(`(.*)App_Resources(.*)`)]);
// Makes sure that require.context will never include code from
// another platform (ie .android.ts when building for ios)
const otherPlatformsRE = getAvailablePlatforms()
.filter((platform) => platform !== getPlatformName())
.join('|');
config
.plugin('ContextExclusionPlugin|Other_Platforms')
.use(ContextExclusionPlugin, [
new RegExp(`\\.(${otherPlatformsRE})\\.(\\w+)$`),
]);
// Filter common undesirable warnings
config.set(
'ignoreWarnings',

View File

@@ -1,5 +1,5 @@
import { warnOnce } from './log';
import { env } from '../index';
import { error, warnOnce } from './log';
function getCLILib() {
if (!env.nativescriptLibPath) {
@@ -28,7 +28,9 @@ export function getValue<T = any>(key: string, defaultValue?: any): T {
return defaultValue;
}
return (lib.projectConfigService as {
getValue(key: string, defaultValue?: any): T;
}).getValue(key, defaultValue);
return (
lib.projectConfigService as {
getValue(key: string, defaultValue?: any): T;
}
).getValue(key, defaultValue);
}

View File

@@ -2,6 +2,7 @@ import { dirname, resolve } from 'path';
import { getPackageJson, getProjectRootPath } from './project';
import { error, info, warnOnce } from './log';
import { getValue } from './config';
import { env } from '../';
import AndroidPlatform from '../platforms/android';
@@ -40,6 +41,13 @@ export function getPlatform(): INativeScriptPlatform {
return platforms[getPlatformName()];
}
/**
* Utility to get all registered/available platforms
*/
export function getAvailablePlatforms(): string[] {
return Object.keys(platforms);
}
/**
* Utility to get the currently targeted platform name
*/
@@ -61,7 +69,7 @@ export function getPlatformName(): Platform {
throw error(`
Invalid platform: ${env.platform}
Valid platforms: ${Object.keys(platforms).join(', ')}
Valid platforms: ${getAvailablePlatforms().join(', ')}
`);
}
@@ -92,6 +100,13 @@ export function getEntryPath() {
return platform.getEntryPath();
}
// try main from nativescript.config.ts
const main = getValue('main');
if (main) {
return resolve(getProjectRootPath(), main);
}
// fallback to main field in package.json
const packageJson = getPackageJson();

View File

@@ -43,8 +43,12 @@ export interface IWebpackEnv {
// enable verbose output
verbose?: boolean;
// enable webpack profiling
profile?: boolean;
// misc
replace?: string[] | string;
watchNodeModules?: boolean;
}
interface IChainEntry {

View File

@@ -75,16 +75,22 @@ async function parseXML(content: string): Promise<ParseResult> {
const resolvePaths = [
localNamespacePath,
localModulePath,
`${localModulePath}.xml`,
moduleName,
namespace,
`${moduleName}.xml`,
`~/${moduleName}`,
`~/${namespace}`,
];
// fallbacks for codeless namespaces
const fallbackResolvePaths = [
`${localModulePath}.xml`,
`${moduleName}.xml`,
`~/${moduleName}.xml`,
];
DEBUG && console.log({ resolvePaths });
DEBUG && console.log({ resolvePaths, fallbackResolvePaths });
let resolvedPath;
let isFallbackPath = false;
for (const p of resolvePaths) {
resolvedPath = await resolveAsync(this.context, p).catch(noop);
@@ -95,7 +101,23 @@ async function parseXML(content: string): Promise<ParseResult> {
}
}
DEBUG && console.log({ resolvedPath });
if (!resolvedPath) {
for (const p of fallbackResolvePaths) {
resolvedPath = await resolveAsync(this.context, p).catch(noop);
// break on first match
if (resolvedPath) {
isFallbackPath = true;
break;
}
}
}
DEBUG &&
console.log({
resolvedPath,
isFallbackPath,
});
// bail if we haven't resolved a path
if (!resolvedPath) {
@@ -104,10 +126,15 @@ async function parseXML(content: string): Promise<ParseResult> {
const { dir, name } = parse(resolvedPath);
// register resolved path + short name
namespaces.push({ name: namespace, path: resolvedPath });
namespaces.push({ name: moduleName, path: resolvedPath });
this.addDependency(resolvedPath);
DEBUG && console.log({ namespace, moduleName });
// check if we are not in a fallback path, in which case we shouldn't register it as a namespace
if (!isFallbackPath) {
// register resolved path + short name
namespaces.push({ name: namespace, path: resolvedPath });
namespaces.push({ name: moduleName, path: resolvedPath });
this.addDependency(resolvedPath);
}
const noExtFilename = join(dir, name);