@vivocha/public-entities
Advanced tools
Comparing version 5.9.8 to 5.9.9
@@ -0,1 +1,38 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Sass = require("sass.js/dist/sass.js"); | ||
const widget_1 = require("./widget"); | ||
// TODO figure out where to get this file from | ||
//Sass.setWorkerUrl('https://raw.githubusercontent.com/medialize/sass.js/master/dist/sass.worker.js'); | ||
Sass.setWorkerUrl('node_modules/sass.js/dist/sass.worker.js'); | ||
class BrowserWidgetInstance extends widget_1.WidgetInstanceWrapper { | ||
renderSass(scss) { | ||
const sass = new Sass(); | ||
sass.importer((request, done) => { | ||
console.log('importer', request); | ||
(async () => { | ||
done({ content: await this.fetchAsset(this.resolveAssetUrl(request.current, request.previous)) }); | ||
})(); | ||
}); | ||
return new Promise((resolve, reject) => { | ||
sass.options({ | ||
style: Sass.style.compressed | ||
}, () => { | ||
sass.compile(scss, result => { | ||
if (result.status !== 0) { | ||
reject(result.status); | ||
} | ||
else { | ||
resolve(result.text); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
async fetchAsset(url) { | ||
const response = await fetch(url); | ||
return response.text(); | ||
} | ||
} | ||
exports.BrowserWidgetInstance = BrowserWidgetInstance; | ||
//# sourceMappingURL=widget_browser.js.map |
@@ -1,12 +0,5 @@ | ||
import { Asset } from '../widget'; | ||
import { WidgetInstanceCreateOptions, WidgetInstanceWrapper } from './widget'; | ||
export interface AssetMap { | ||
[key: string]: Asset; | ||
} | ||
import { WidgetInstanceWrapper } from './widget'; | ||
export declare class NodeWidgetInstance extends WidgetInstanceWrapper { | ||
constructor(options: WidgetInstanceCreateOptions); | ||
readonly assetsByPath: AssetMap; | ||
renderSass(scss: string): Promise<string>; | ||
resolveAssetUrl(url: string, base?: string): string; | ||
fetchAsset(url: string): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("util"); | ||
const url_1 = require("url"); | ||
const request = require("request"); | ||
@@ -9,19 +8,7 @@ const node_sass_1 = require("node-sass"); | ||
const render = util_1.promisify(node_sass_1.render); | ||
const __assetsByPath = Symbol(); | ||
const __assetsRegExp = /^(?:\.\/)?(assets\/.*)$/; | ||
class NodeWidgetInstance extends widget_1.WidgetInstanceWrapper { | ||
constructor(options) { | ||
super(options); | ||
this[__assetsByPath] = (options.manifest.assets || []).reduce((o, i) => { | ||
o[i.path] = i; | ||
return o; | ||
}, {}); | ||
} | ||
get assetsByPath() { | ||
return this[__assetsByPath]; | ||
} | ||
async renderSass(scss) { | ||
return (await render({ | ||
data: scss, | ||
//outputStyle: 'compressed', | ||
outputStyle: 'compressed', | ||
importer: (url, prev, done) => { | ||
@@ -35,20 +22,2 @@ console.log('importer', url, prev); | ||
} | ||
resolveAssetUrl(url, base) { | ||
let resolvedURL = url; | ||
if (base && base !== 'stdin') { | ||
resolvedURL = (new url_1.URL(url, `x://y/${base}`)).toString().substr(6); | ||
} | ||
const match = resolvedURL.match(__assetsRegExp); | ||
if (match && match.length > 1) { | ||
let asset = this.assetsByPath[match[1]] || this.assetsByPath[match[1] + '.scss'] || this.assetsByPath[match[1] + '.css']; | ||
if (asset) { | ||
resolvedURL = (new url_1.URL(asset.id, this.options.assetsBaseUrl)).toString(); | ||
} | ||
else { | ||
console.error('unknown asset', match[1]); | ||
throw new Error('unknown_asset'); | ||
} | ||
} | ||
return resolvedURL; | ||
} | ||
fetchAsset(url) { | ||
@@ -55,0 +24,0 @@ return new Promise((resolve, reject) => { |
@@ -1,2 +0,5 @@ | ||
import { WidgetManifest, WidgetSettings, WidgetInstance } from '../widget'; | ||
import { Asset, WidgetManifest, WidgetSettings, WidgetInstance } from '../widget'; | ||
export interface AssetMap { | ||
[key: string]: Asset; | ||
} | ||
export interface WidgetInstanceFactory { | ||
@@ -20,4 +23,5 @@ new (options: WidgetInstanceCreateOptions): WidgetInstanceWrapper; | ||
readonly options: WidgetInstanceCreateOptions; | ||
readonly assetsByPath: AssetMap; | ||
resolveAssetUrl(url: string, base?: string): string; | ||
abstract renderSass(scss: string): Promise<string>; | ||
abstract resolveAssetUrl(url: string, base?: string): string; | ||
abstract fetchAsset(url: string): Promise<any>; | ||
@@ -24,0 +28,0 @@ create(): Promise<WidgetInstance>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const URL = require("url"); | ||
const eredita_1 = require("eredita"); | ||
const language_1 = require("./language"); | ||
const __options = Symbol(); | ||
const __assetsByPath = Symbol(); | ||
const __assetsRegExp = /^(?:\.\/)?(assets\/.*)$/; | ||
class WidgetInstanceWrapper { | ||
constructor(options) { | ||
this[__options] = options; | ||
this[__assetsByPath] = (options.manifest.assets || []).reduce((o, i) => { | ||
o[i.path] = i; | ||
return o; | ||
}, {}); | ||
} | ||
@@ -13,2 +20,23 @@ get options() { | ||
} | ||
get assetsByPath() { | ||
return this[__assetsByPath]; | ||
} | ||
resolveAssetUrl(url, base) { | ||
let resolvedURL = url; | ||
if (base && base !== 'stdin') { | ||
resolvedURL = URL.resolve(`x://y/${base}`, url).substr(6); | ||
} | ||
const match = resolvedURL.match(__assetsRegExp); | ||
if (match && match.length > 1) { | ||
let asset = this.assetsByPath[match[1]] || this.assetsByPath[match[1] + '.scss'] || this.assetsByPath[match[1] + '.css']; | ||
if (asset) { | ||
resolvedURL = URL.resolve(this.options.assetsBaseUrl, asset.id); | ||
} | ||
else { | ||
console.error('unknown asset', match[1]); | ||
throw new Error('unknown_asset'); | ||
} | ||
} | ||
return resolvedURL; | ||
} | ||
async create() { | ||
@@ -15,0 +43,0 @@ let out = { |
{ | ||
"name": "@vivocha/public-entities", | ||
"version": "5.9.8", | ||
"version": "5.9.9", | ||
"description": "Vivocha public entities and types", | ||
@@ -42,12 +42,13 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/node": "^8.0.47", | ||
"@types/node": "^8.0.49", | ||
"@types/node-sass": "^3.10.32", | ||
"jsonref-cli": "^1.0.0", | ||
"typescript": "^2.5.3" | ||
"typescript": "^2.6.1" | ||
}, | ||
"dependencies": { | ||
"eredita": "^1.1.4", | ||
"node-sass": "^4.5.3", | ||
"request": "^2.83.0" | ||
"node-sass": "^4.6.0", | ||
"request": "^2.83.0", | ||
"sass.js": "^0.10.6" | ||
} | ||
} |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
31384
888
4
1
+ Addedsass.js@^0.10.6
+ Addedsass.js@0.10.13(transitive)
Updatednode-sass@^4.6.0