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

fix: remove tns-core-modules dependency in order to allow @nativescrip/core migration #1091

Merged
merged 1 commit into from
Nov 8, 2019
Merged
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
12 changes: 4 additions & 8 deletions css2json-loader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { parse, Rule, SyntaxTree } from "tns-core-modules/css";
import { parse, Import, Stylesheet } from "css";
import { loader } from "webpack";
import { getOptions } from "loader-utils";

interface ImportRule extends Rule {
import: string;
}

const betweenQuotesPattern = /('|")(.*?)\1/;
const unpackUrlPattern = /url\(([^\)]+)\)/;
const inlineLoader = "!nativescript-dev-webpack/css2json-loader?useForImports!"
Expand Down Expand Up @@ -33,18 +29,18 @@ const loader: loader.Loader = function (content: string, map) {
this.callback(null, `${dependencies.join("\n")}module.exports = ${str};`, map);
}

function getImportRules(ast: SyntaxTree): ImportRule[] {
function getImportRules(ast: Stylesheet): Import[] {
if (!ast || (<any>ast).type !== "stylesheet" || !ast.stylesheet) {
return [];
}
return <ImportRule[]>ast.stylesheet.rules
return <Import[]>ast.stylesheet.rules
.filter(rule => rule.type === "import" && (<any>rule).import)
}

/**
* Extracts the url from import rule (ex. `url("./platform.css")`)
*/
function extractUrlFromRule(importRule: ImportRule): string {
function extractUrlFromRule(importRule: Import): string {
const urlValue = importRule.import;

const unpackedUrlMatch = urlValue.match(unpackUrlPattern);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@angular-devkit/core": "8.2.0",
"clean-webpack-plugin": "~1.0.0",
"copy-webpack-plugin": "~4.6.0",
"css": "2.2.1",
"css-loader": "~2.1.1",
"escape-string-regexp": "1.0.5",
"fork-ts-checker-webpack-plugin": "2.0.0",
Expand Down Expand Up @@ -82,6 +83,7 @@
"@angular/compiler-cli": "8.2.0",
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@ngtools/webpack": "8.2.0",
"@types/css": "0.0.31",
"@types/jasmine": "^3.3.7",
"@types/loader-utils": "^1.1.3",
"@types/node": "^10.12.12",
Expand Down