Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestApp</string>
<string name="title_activity_kimera">TestApp</string>
<string name="app_name">FileQualifiers</string>
<string name="title_activity_kimera">FileQualifiers</string>
</resources>
4 changes: 1 addition & 3 deletions e2e/file-qualifiers/nsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"useLegacyWorkflow": false
}
{}
4 changes: 2 additions & 2 deletions e2e/file-qualifiers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"nativescript": {
"id": "org.nativescript.filequalifiers",
"tns-ios": {
"version": "6.0.0-2019-06-19-084246-01"
"version": "next"
},
"tns-android": {
"version": "6.0.0-2019-06-24-113546-01"
"version": "next"
}
},
"dependencies": {
Expand Down
9 changes: 5 additions & 4 deletions e2e/file-qualifiers/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = env => {

// Default destination inside platforms/<platform>/...
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";

const {
// The 'appPath' and 'appResourcesPath' values are fetched from
Expand Down Expand Up @@ -73,6 +72,7 @@ module.exports = env => {
itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`);
}

nsWebpack.processAppComponents(appComponents, platform);
const config = {
mode: production ? "production" : "development",
context: appFullPath,
Expand Down Expand Up @@ -179,13 +179,14 @@ module.exports = env => {
unitTesting,
appFullPath,
projectRoot,
ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
}
},
].filter(loader => !!loader)
},

{
test: /\.(ts|css|scss|less|html|xml)$/,
test: /\.(ts|css|scss|html|xml)$/,
use: "nativescript-dev-webpack/hmr/hot-loader"
},

Expand Down Expand Up @@ -227,7 +228,7 @@ module.exports = env => {
// Define useful constants like TNS_WEBPACK
new webpack.DefinePlugin({
"global.TNS_WEBPACK": "true",
"process": undefined,
"process": "global.process",
}),
// Remove all files from the out dir.
new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
Expand Down
19 changes: 9 additions & 10 deletions tests/app/ui/label/label-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,15 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
}

// TODO: fix this, broken with https://github.com/NativeScript/NativeScript/pull/7499
// public testErrorMessageWhenWrongCssIsAddedWithFile() {
// const view = this.testView;
// const page = this.testPage;
// this.waitUntilTestElementIsLoaded();

// view.id = "testLabel";
// page.addCssFile(fs.path.join(testDir, "label-tests-wrong-page.css"));
// TKUnit.assertNotEqual(this.errorMessage, undefined);
// }
public testErrorMessageWhenWrongCssIsAddedWithFile() {
const view = this.testView;
const page = this.testPage;
this.waitUntilTestElementIsLoaded();

view.id = "testLabel";
page.addCssFile(fs.path.join(testDir, "label-tests-wrong-page.css"));
TKUnit.assertNotEqual(this.errorMessage, undefined);
}

public testErrorMessageWhenWrongCssIsAdded() {
const view = this.testView;
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/application/application-common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Require globals first so that snapshot takes __extends function.
require("globals");
import "../globals";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is difference here? We have this in a lot of doc files in the API reference i believe.

@vakrilov vakrilov Jul 24, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webpack is strange and creates code for all "import" statements at the start of the module. So all the imports that are after require("globals") actually get executed before it in the generated bundle.
This happens with when modules are linked and TS is compiled by webpack.

@MartoYankov MartoYankov Jul 24, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's the reason we got so many circular refs with the webpack plugin for circular refs. @manoldonev


import { Observable, EventData } from "../data/observable";
import { View } from "../ui/core/view";
Expand Down
9 changes: 9 additions & 0 deletions tns-core-modules/module-name-resolver/module-name-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { screen, device } from "../platform/platform";
import * as appCommonModule from "../application/application-common";
import { PlatformContext, findMatch } from "./qualifier-matcher";
import { registerModulesFromFileSystem } from "./non-bundle-workflow-compat";
import {
isEnabled as traceEnabled,
write as traceWrite,
categories as traceCategories
} from "../trace";

export class ModuleNameResolver implements ModuleNameResolverDefinition {
private _cache = {};
Expand All @@ -18,6 +23,10 @@ export class ModuleNameResolver implements ModuleNameResolverDefinition {
this._cache[key] = result;
}

if (traceEnabled()) {
traceWrite(`path: '${path}' with ext: '${ext}' resolved: '${result}'`, traceCategories.ModuleNameResolver);
}

return result;
}

Expand Down
49 changes: 32 additions & 17 deletions tns-core-modules/module-name-resolver/non-bundle-workflow-compat.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import * as fs from "../file-system/file-system";
import * as appCommonModule from "../application/application-common";
import {
isEnabled as traceEnabled,
write as traceWrite,
categories as traceCategories
} from "../trace";

const cache = new Set<string>();
let initialized = false;

function register(name, loader) {
function register(name: string, loader: (name?: string) => void) {
if (traceEnabled()) {
traceWrite(`[Compat] Register module: ${name}`, traceCategories.ModuleNameResolver);
}
global.registerModule(name, loader);

if (name.startsWith("tns_modules")) {
const nonTnsModulesName = name.substr("tns_modules".length + 1);
if (traceEnabled()) {
traceWrite(`[Compat] Register module: ${nonTnsModulesName}`, traceCategories.ModuleNameResolver);
}
global.registerModule(nonTnsModulesName, loader);
}
}

function processFile(file: fs.File) {
Expand Down Expand Up @@ -35,16 +51,21 @@ function processFile(file: fs.File) {
let name = filePathRelativeToApp.substr(0, filePathRelativeToApp.length - "package.json".length - 1);
let requirePath = fs.path.join(file.parent.path, json.main);

if (name.startsWith("tns_modules")) {
name = name.substr("tns_modules".length + 1);
}

register(name, () => global.require(requirePath));
}
}
}

function processFolder(path: string) {
if (cache.has(path)) {
return;
}
cache.add(path);

if (traceEnabled()) {
traceWrite(`[Compat] Processing folder: ${path}`, traceCategories.ModuleNameResolver);
}

if (fs.Folder.exists(path)) {
const folder = fs.Folder.fromPath(path);

Expand All @@ -66,43 +87,37 @@ function processFolder(path: string) {
export function registerModulesFromFileSystem(moduleName: string) {
initialize();

if (cache.has(moduleName)) {
return;
}
cache.add(moduleName);

let folderFound = false;
// moduleName is a folder with package.json
const path = fs.path.join(fs.knownFolders.currentApp().path, moduleName);
if (fs.Folder.exists(path)) {
processFolder(path);

return;
folderFound = true;
}

// moduleName is file - load all files in it's folder
// moduleName is file - load all files in its parent folder
const parentName = moduleName.substr(0, moduleName.lastIndexOf(fs.path.separator));
const parentFolderPath = fs.path.join(fs.knownFolders.currentApp().path, parentName);
if (fs.Folder.exists(parentFolderPath)) {
processFolder(parentFolderPath);
folderFound = true;
}

if (folderFound) {
Comment thread
MartoYankov marked this conversation as resolved.
return;
}

// moduleName is a folder in tns_modules ex. "nativescript-ui-chart"
const tnsModulesPath = fs.path.join(fs.knownFolders.currentApp().path, "tns_modules", moduleName);
if (fs.Folder.exists(tnsModulesPath)) {
processFolder(tnsModulesPath);

return;
}

// moduleName a file in tns_modules/plugin. Avoid traversing the whole tns_modules folder if parentName is empty
if (parentName) {
const tnsParentFolderPath = fs.path.join(fs.knownFolders.currentApp().path, "tns_modules", parentName);
if (fs.Folder.exists(tnsParentFolderPath)) {
processFolder(tnsParentFolderPath);

return;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tns-core-modules/trace/trace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export module categories {
export const Animation: string;
export const Transition: string;
export const Livesync: string;
export const ModuleNameResolver: string;

export const separator: string;
export const All: string;
Expand Down
21 changes: 8 additions & 13 deletions tns-core-modules/trace/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,16 @@ export module categories {
export const Animation = "Animation";
export const Transition = "Transition";
export const Livesync = "Livesync";
export const ModuleNameResolver = "ModuleNameResolver";

export const separator = ",";
export const All = VisualTreeEvents + separator
+ Layout + separator
+ Style + separator
+ ViewHierarchy + separator
+ NativeLifecycle + separator
+ Debug + separator
+ Navigation + separator
+ Test + separator
+ Binding + separator
+ Error + separator
+ Animation + separator
+ Transition + separator
+ Livesync;
export const All = [
VisualTreeEvents, Layout, Style,
ViewHierarchy, NativeLifecycle,
Debug, Navigation, Test, Binding,
Error, Animation, Transition, Livesync,
ModuleNameResolver]
.join(separator);
Comment thread
MartoYankov marked this conversation as resolved.

export function concat(): string {
let result: string;
Expand Down
2 changes: 2 additions & 0 deletions tns-core-modules/ui/builder/module-name-sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export function sanitizeModuleName(moduleName: string, removeExtension: boolean

if (moduleName.startsWith("~/")) {
moduleName = moduleName.substring(2);
} else if (moduleName.startsWith("~")) {
moduleName = moduleName.substring(1);
} else if (moduleName.startsWith("/")) {
moduleName = moduleName.substring(1);
}
Expand Down
34 changes: 22 additions & 12 deletions tns-core-modules/ui/styling/style-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function ensureKeyframeAnimationModule() {
}

import * as capm from "./css-animation-parser";
import { sanitizeModuleName } from "../builder/module-name-sanitizer";
import { resolveModuleName } from "../../module-name-resolver";
Comment thread
MartoYankov marked this conversation as resolved.
let cssAnimationParserModule: typeof capm;
function ensureCssAnimationParserModule() {
if (!cssAnimationParserModule) {
Expand Down Expand Up @@ -80,25 +82,26 @@ class CSSSource {

public static fromURI(uri: string, keyframes: KeyframesMap): CSSSource {
// webpack modules require all file paths to be relative to /app folder
let appRelativeUri = CSSSource.pathRelativeToApp(uri);
const appRelativeUri = CSSSource.pathRelativeToApp(uri);
const sanitizedModuleName = sanitizeModuleName(appRelativeUri);
const resolvedModuleName = resolveModuleName(sanitizedModuleName, "css");

try {
const cssOrAst = global.loadModule(appRelativeUri, true);
const cssOrAst = global.loadModule(resolvedModuleName, true);
if (cssOrAst) {
if (typeof cssOrAst === "string") {
// raw-loader
return CSSSource.fromSource(cssOrAst, keyframes, appRelativeUri);
return CSSSource.fromSource(cssOrAst, keyframes, resolvedModuleName);
} else if (typeof cssOrAst === "object" && cssOrAst.type === "stylesheet" && cssOrAst.stylesheet && cssOrAst.stylesheet.rules) {
// css-loader
return CSSSource.fromAST(cssOrAst, keyframes, appRelativeUri);
return CSSSource.fromAST(cssOrAst, keyframes, resolvedModuleName);
} else {
// css2json-loader
return CSSSource.fromSource(cssOrAst.toString(), keyframes, appRelativeUri);
return CSSSource.fromSource(cssOrAst.toString(), keyframes, resolvedModuleName);
}
}
} catch (e) {
// TODO: Commented as this prints error in playground: https://github.com/NativeScript/NativeScript/issues/7497
// traceWrite(`Could not load CSS from ${uri}: ${e}`, traceCategories.Error, traceMessageType.error);
traceWrite(`Could not load CSS from ${uri}: ${e}`, traceCategories.Error, traceMessageType.error);
}

return CSSSource.fromFile(appRelativeUri, keyframes);
Expand Down Expand Up @@ -320,12 +323,17 @@ function onLiveSync(args: applicationCommon.CssChangedEventData): void {
loadCss(applicationCommon.getCssFileName());
}

const loadCss = profile(`"style-scope".loadCss`, (cssFile: string) => {
if (!cssFile) {
const loadCss = profile(`"style-scope".loadCss`, (cssModule: string) => {
if (!cssModule) {
return undefined;
}

const result = CSSSource.fromURI(cssFile, applicationKeyframes).selectors;
// safely remove "./" as global CSS should be resolved relative to app folder
if (cssModule.startsWith("./")) {
cssModule = cssModule.substr(2);
}

const result = CSSSource.fromURI(cssModule, applicationKeyframes).selectors;
if (result.length > 0) {
applicationSelectors = result;
mergeCssSelectors();
Expand All @@ -336,8 +344,10 @@ applicationCommon.on("cssChanged", onCssChanged);
applicationCommon.on("livesync", onLiveSync);

export const loadAppCSS = profile("\"style-scope\".loadAppCSS", (args: applicationCommon.LoadAppCSSEventData) => {
loadCss(args.cssFile);
applicationCommon.off("loadAppCss", loadAppCSS);
if (applicationCommon.hasLaunched()) {
Comment thread
MartoYankov marked this conversation as resolved.
loadCss(args.cssFile);
applicationCommon.off("loadAppCss", loadAppCSS);
}
});

if (applicationCommon.hasLaunched()) {
Expand Down
1 change: 0 additions & 1 deletion tns-core-modules/xml/xml.js

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