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

Commit

Permalink
fix: remove the tns-core-modules dependency in order to allow @native…
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarTachev committed Nov 8, 2019
1 parent 76fe655 commit 7d60958
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
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

0 comments on commit 7d60958

Please sign in to comment.