update
This commit is contained in:
+10
@@ -1,3 +1,13 @@
|
||||
## 1.5.0 (December 8, 2021)
|
||||
|
||||
* Injector function is called with `this` context pointing to the loader context.
|
||||
|
||||
## 1.4.0 ~ 1.4.1 (November 17, 2020)
|
||||
|
||||
* Support webpack 5. [#29](https://github.com/yenshih/style-resources-loader/issues/29)
|
||||
|
||||
* Fix some issues. [#30](https://github.com/yenshih/style-resources-loader/issues/30)
|
||||
|
||||
## 1.3.3 (December 19, 2019)
|
||||
|
||||
* Fix resource files cache invalidation problems on Windows. [#17](https://github.com/yenshih/style-resources-loader/issues/17)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Shi Yan
|
||||
Copyright (c) Yan Shi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
+19
-13
@@ -120,10 +120,10 @@ module.exports = {
|
||||
|
||||
|Name|Type|Default|Description|
|
||||
|:--:|:--:|:-----:|:----------|
|
||||
|**[`patterns`](#patterns)**|`{string \| string[]}`|`/`|Path to the resources you would like to inject|
|
||||
|**[`injector`](#injector)**|`{Function \| 'prepend' \| 'append'}`|`'prepend'`|Controls the resources injection precisely|
|
||||
|**[`globOptions`](#globoptions)**|`{Object}`|`{}`|An options that can be passed to `glob(...)`|
|
||||
|**[`resolveUrl`](#resolveurl)**|`{boolean}`|`true`|Enable/Disable `@import` url to be resolved|
|
||||
|**[`patterns`](#patterns)**|`string \| string[]`|`/`|Path to the resources you would like to inject|
|
||||
|**[`injector`](#injector)**|`Injector \| 'prepend' \| 'append'`|`'prepend'`|Controls the resources injection precisely|
|
||||
|**[`globOptions`](#globoptions)**|`GlobOptions`|`{}`|An options that can be passed to `glob(...)`|
|
||||
|**[`resolveUrl`](#resolveurl)**|`boolean`|`true`|Enable/Disable `@import` url to be resolved|
|
||||
|
||||
See [the type definition file](https://github.com/yenshih/style-resources-loader/blob/master/src/types.ts) for more details.
|
||||
|
||||
@@ -157,24 +157,30 @@ It defaults to `'prepend'`, which implements as an injector function internally.
|
||||
Furthermore, an injector function should match the following type signature:
|
||||
|
||||
```ts
|
||||
(source: string, resources: StyleResource[]) => string | Promise<string>
|
||||
type Injector = (
|
||||
this: LoaderContext,
|
||||
source: string,
|
||||
resources: StyleResource[],
|
||||
) => string | Promise<string>
|
||||
```
|
||||
|
||||
It receives two parameters:
|
||||
|
||||
|Name|Type|Default|Description|
|
||||
|:--:|:--:|:-----:|:----------|
|
||||
|**`source`**|`{string}`|`/`|Content of the source file|
|
||||
|**[`resources`](#resources)**|`{StyleResource[]}`|`/`|Resource descriptors|
|
||||
|Name|Type|Description|
|
||||
|:--:|:--:|:----------|
|
||||
|**`source`**|`string`|Content of the source file|
|
||||
|**[`resources`](#resources)**|`StyleResource[]`|Resource descriptors|
|
||||
|
||||
It is called with `this` context pointing to the loader context.
|
||||
|
||||
#### `resources`
|
||||
|
||||
An array of resource descriptor, each contains `file` and `content` properties:
|
||||
|
||||
|Name|Type|Default|Description|
|
||||
|:--:|:--:|:-----:|:----------|
|
||||
|**`file`**|`{string}`|`/`|Absolute path to the resource|
|
||||
|**`content`**|`{string}`|`/`|Content of the resource file|
|
||||
|Name|Type|Description|
|
||||
|:--:|:--:|:----------|
|
||||
|**`file`**|`string`|Absolute path to the resource|
|
||||
|**`content`**|`string`|Content of the resource file|
|
||||
|
||||
It can be asynchronous. You could use `async / await` syntax in your own injector function or just return a promise.
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
import loader from './loader';
|
||||
export * from './schema';
|
||||
export * from './types';
|
||||
export default loader;
|
||||
|
||||
+3
-8
@@ -1,12 +1,7 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const loader_1 = __importDefault(require("./loader"));
|
||||
__export(require("./schema"));
|
||||
const tslib_1 = require("tslib");
|
||||
const loader_1 = (0, tslib_1.__importDefault)(require("./loader"));
|
||||
(0, tslib_1.__exportStar)(require("./types"), exports);
|
||||
exports.default = loader_1.default;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,sDAA8B;AAE9B,8BAAyB;AAGzB,kBAAe,gBAAM,CAAC"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAA8B;AAE9B,uDAAwB;AAExB,kBAAe,gBAAM,CAAC"}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
import { Loader } from '.';
|
||||
import type { Loader } from '.';
|
||||
declare const loader: Loader;
|
||||
export default loader;
|
||||
|
||||
+3
-3
@@ -2,15 +2,15 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("./utils");
|
||||
const loader = function (source) {
|
||||
this.cacheable && this.cacheable();
|
||||
this.cacheable();
|
||||
const callback = this.async();
|
||||
if (!utils_1.isFunction(callback)) {
|
||||
if (!(0, utils_1.isFunction)(callback)) {
|
||||
throw new Error(utils_1.errorMessage.syncCompilation);
|
||||
}
|
||||
if (typeof source !== 'string') {
|
||||
throw new Error(utils_1.errorMessage.impossible);
|
||||
}
|
||||
utils_1.loadResources(this, source, callback);
|
||||
void (0, utils_1.loadResources)(this, source, callback);
|
||||
};
|
||||
exports.default = loader;
|
||||
//# sourceMappingURL=loader.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;AAAA,mCAAgE;AAKhE,MAAM,MAAM,GAAW,UAAS,MAAM;IAClC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;IAEnC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAE9B,IAAI,CAAC,kBAAU,CAAiB,QAAQ,CAAC,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,oBAAY,CAAC,eAAe,CAAC,CAAC;KACjD;IAGD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,oBAAY,CAAC,UAAU,CAAC,CAAC;KAC5C;IAGD,qBAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC1C,CAAC,CAAC;AAGF,kBAAe,MAAM,CAAC"}
|
||||
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;AAAA,mCAAgE;AAIhE,MAAM,MAAM,GAAW,UAAU,MAAM;IACnC,IAAI,CAAC,SAAS,EAAE,CAAC;IAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAE9B,IAAI,CAAC,IAAA,kBAAU,EAAiB,QAAQ,CAAC,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,oBAAY,CAAC,eAAe,CAAC,CAAC;KACjD;IAGD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,oBAAY,CAAC,UAAU,CAAC,CAAC;KAC5C;IAED,KAAK,IAAA,qBAAa,EAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import validate from 'schema-utils';
|
||||
import type validate from 'schema-utils';
|
||||
declare type Schema = Parameters<typeof validate>[0];
|
||||
export declare const schema: Schema;
|
||||
export {};
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.schema = void 0;
|
||||
exports.schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;AAIa,QAAA,MAAM,GAAW;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,QAAQ,EAAE;YACN,KAAK,EAAE;gBACH,EAAC,IAAI,EAAE,QAAQ,EAAC;gBAChB;oBACI,IAAI,EAAE,OAAO;oBACb,WAAW,EAAE,IAAI;oBACjB,KAAK,EAAE;wBACH,IAAI,EAAE,QAAQ;qBACjB;iBACJ;aACJ;SACJ;QACD,QAAQ,EAAE;YACN,KAAK,EAAE;gBACH;oBACI,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;iBAC9B;gBACD;oBACI,UAAU,EAAE,UAAU;iBACzB;aACJ;SACJ;QACD,WAAW,EAAE;YACT,IAAI,EAAE,QAAQ;SACjB;QACD,UAAU,EAAE;YACR,IAAI,EAAE,SAAS;SAClB;KACJ;IACD,QAAQ,EAAE,CAAC,UAAU,CAAC;IACtB,oBAAoB,EAAE,KAAK;CAC9B,CAAC"}
|
||||
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AAIa,QAAA,MAAM,GAAW;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,QAAQ,EAAE;YACN,KAAK,EAAE;gBACH,EAAC,IAAI,EAAE,QAAQ,EAAC;gBAChB;oBACI,IAAI,EAAE,OAAO;oBACb,WAAW,EAAE,IAAI;oBACjB,KAAK,EAAE;wBACH,IAAI,EAAE,QAAQ;qBACjB;iBACJ;aACJ;SACJ;QACD,QAAQ,EAAE;YACN,KAAK,EAAE;gBACH;oBACI,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;iBAC9B;gBACD;oBACI,UAAU,EAAE,UAAU;iBACzB;aACJ;SACJ;QACD,WAAW,EAAE;YACT,IAAI,EAAE,QAAQ;SACjB;QACD,UAAU,EAAE;YACR,IAAI,EAAE,SAAS;SAClB;KACJ;IACD,QAAQ,EAAE,CAAC,UAAU,CAAC;IACtB,oBAAoB,EAAE,KAAK;CAC9B,CAAC"}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { loader } from 'webpack';
|
||||
import glob from 'glob';
|
||||
import type { loader } from 'webpack';
|
||||
import type glob from 'glob';
|
||||
export declare type Loader = loader.Loader;
|
||||
export declare type LoaderContext = loader.LoaderContext;
|
||||
export declare type LoaderCallback = loader.loaderCallback;
|
||||
@@ -9,7 +9,7 @@ export interface StyleResource {
|
||||
content: string;
|
||||
}
|
||||
export declare type StyleResources = StyleResource[];
|
||||
export declare type StyleResourcesFunctionalInjector = (source: string, resources: StyleResources) => string | Promise<string>;
|
||||
export declare type StyleResourcesFunctionalInjector = (this: LoaderContext, source: string, resources: StyleResources) => string | Promise<string>;
|
||||
export declare type StyleResourcesInjector = 'prepend' | 'append' | StyleResourcesFunctionalInjector;
|
||||
export declare type StyleResourcesNormalizedInjector = StyleResourcesFunctionalInjector;
|
||||
export interface StyleResourcesLoaderOptions {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { StyleResourcesFileFormat } from '..';
|
||||
import type { StyleResourcesFileFormat } from '../types';
|
||||
export declare const PACKAGE_NAME = "style-resources-loader";
|
||||
export declare const ISSUES_URL: string;
|
||||
export declare const LOADER_NAME: string;
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SUPPORTED_FILE_EXTS = exports.SUPPORTED_FILE_FORMATS = exports.VALIDATION_BASE_DATA_PATH = exports.LOADER_NAME = exports.ISSUES_URL = exports.PACKAGE_NAME = void 0;
|
||||
exports.PACKAGE_NAME = 'style-resources-loader';
|
||||
exports.ISSUES_URL = `https://github.com/yenshih/${exports.PACKAGE_NAME}/issues`;
|
||||
exports.LOADER_NAME = exports.PACKAGE_NAME.split('-')
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;AAEa,QAAA,YAAY,GAAG,wBAAwB,CAAC;AAExC,QAAA,UAAU,GAAG,8BAA8B,oBAAY,SAAS,CAAC;AAEjE,QAAA,WAAW,GAAG,oBAAY,CAAC,KAAK,CAAC,GAAG,CAAC;KAC7C,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,IAAI,CAAC,GAAG,CAAC,CAAC;AAEF,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEtC,QAAA,sBAAsB,GAA+B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7F,QAAA,mBAAmB,GAAG,8BAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC"}
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,YAAY,GAAG,wBAAwB,CAAC;AAExC,QAAA,UAAU,GAAG,8BAA8B,oBAAY,SAAS,CAAC;AAEjE,QAAA,WAAW,GAAG,oBAAY,CAAC,KAAK,CAAC,GAAG,CAAC;KAC7C,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,IAAI,CAAC,GAAG,CAAC,CAAC;AAEF,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEtC,QAAA,sBAAsB,GAA+B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7F,QAAA,mBAAmB,GAAG,8BAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC"}
|
||||
+4
-3
@@ -1,9 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = require(".");
|
||||
const formatErrorMessage = (message) => `[${_1.PACKAGE_NAME}] ${message}`;
|
||||
exports.errorMessage = void 0;
|
||||
const constants_1 = require("./constants");
|
||||
const formatErrorMessage = (message) => `[${constants_1.PACKAGE_NAME}] ${message}`;
|
||||
const messageByType = {
|
||||
impossible: `This error is caused by a bug. Please file an issue: ${_1.ISSUES_URL}.`,
|
||||
impossible: `This error is caused by a bug. Please file an issue: ${constants_1.ISSUES_URL}.`,
|
||||
syncCompilation: 'Synchronous compilation is not supported.',
|
||||
invalidInjectorReturn: 'Expected options.injector(...) returns a string. Instead received number.',
|
||||
};
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"error-message.js","sourceRoot":"","sources":["../../src/utils/error-message.ts"],"names":[],"mappings":";;AAAA,wBAA2C;AAE3C,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,eAAY,KAAK,OAAO,EAAE,CAAC;AAE/E,MAAM,aAAa,GAAG;IAClB,UAAU,EAAE,wDAAwD,aAAU,GAAG;IACjF,eAAe,EAAE,2CAA2C;IAC5D,qBAAqB,EAAE,2EAA2E;CACrG,CAAC;AAEW,QAAA,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,MAAM,CAC5D,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAChC,GAAG,YAAY;IACf,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC;CACtC,CAAC,EACF,aAAa,CAChB,CAAC"}
|
||||
{"version":3,"file":"error-message.js","sourceRoot":"","sources":["../../src/utils/error-message.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAErD,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,wBAAY,KAAK,OAAO,EAAE,CAAC;AAE/E,MAAM,aAAa,GAAG;IAClB,UAAU,EAAE,wDAAwD,sBAAU,GAAG;IACjF,eAAe,EAAE,2CAA2C;IAC5D,qBAAqB,EAAE,2EAA2E;CACrG,CAAC;AAEW,QAAA,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,MAAM,CAC5D,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAChC,GAAG,YAAY;IACf,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC;CACtC,CAAC,EACF,aAAa,CAChB,CAAC"}
|
||||
+2
-3
@@ -1,3 +1,2 @@
|
||||
/// <reference types="webpack" />
|
||||
import { StyleResource, StyleResourcesLoaderNormalizedOptions } from '..';
|
||||
export declare const getResources: (ctx: import("webpack").loader.LoaderContext, options: StyleResourcesLoaderNormalizedOptions) => Promise<StyleResource[]>;
|
||||
import type { LoaderContext, StyleResource, StyleResourcesLoaderNormalizedOptions } from '../types';
|
||||
export declare const getResources: (ctx: LoaderContext, options: StyleResourcesLoaderNormalizedOptions) => Promise<StyleResource[]>;
|
||||
|
||||
+10
-9
@@ -1,20 +1,21 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const util_1 = __importDefault(require("util"));
|
||||
const _1 = require(".");
|
||||
exports.getResources = async (ctx, options) => {
|
||||
exports.getResources = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
||||
const util_1 = (0, tslib_1.__importDefault)(require("util"));
|
||||
const match_files_1 = require("./match-files");
|
||||
const resolve_import_url_1 = require("./resolve-import-url");
|
||||
const getResources = async (ctx, options) => {
|
||||
const { resolveUrl } = options;
|
||||
const files = await _1.matchFiles(ctx, options);
|
||||
const files = await (0, match_files_1.matchFiles)(ctx, options);
|
||||
files.forEach(file => ctx.dependency(file));
|
||||
const resources = await Promise.all(files.map(async (file) => {
|
||||
const content = await util_1.default.promisify(fs_1.default.readFile)(file, 'utf8');
|
||||
const resource = { file, content };
|
||||
return resolveUrl ? _1.resolveImportUrl(ctx, resource) : resource;
|
||||
return resolveUrl ? (0, resolve_import_url_1.resolveImportUrl)(ctx, resource) : resource;
|
||||
}));
|
||||
return resources;
|
||||
};
|
||||
exports.getResources = getResources;
|
||||
//# sourceMappingURL=get-resources.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"get-resources.js","sourceRoot":"","sources":["../../src/utils/get-resources.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,wBAA+C;AAElC,QAAA,YAAY,GAAG,KAAK,EAAE,GAAkB,EAAE,OAA8C,EAAE,EAAE;IACrG,MAAM,EAAC,UAAU,EAAC,GAAG,OAAO,CAAC;IAE7B,MAAM,KAAK,GAAG,MAAM,aAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAE7C,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;QACnB,MAAM,OAAO,GAAG,MAAM,cAAI,CAAC,SAAS,CAAC,YAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAChE,MAAM,QAAQ,GAAkB,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;QAEhD,OAAO,UAAU,CAAC,CAAC,CAAC,mBAAgB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACnE,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC"}
|
||||
{"version":3,"file":"get-resources.js","sourceRoot":"","sources":["../../src/utils/get-resources.ts"],"names":[],"mappings":";;;;AAAA,yDAAoB;AACpB,6DAAwB;AAIxB,+CAAyC;AACzC,6DAAsD;AAE/C,MAAM,YAAY,GAAG,KAAK,EAAE,GAAkB,EAAE,OAA8C,EAAE,EAAE;IACrG,MAAM,EAAC,UAAU,EAAC,GAAG,OAAO,CAAC;IAE7B,MAAM,KAAK,GAAG,MAAM,IAAA,wBAAU,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAE7C,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;QACnB,MAAM,OAAO,GAAG,MAAM,cAAI,CAAC,SAAS,CAAC,YAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAChE,MAAM,QAAQ,GAAkB,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;QAEhD,OAAO,UAAU,CAAC,CAAC,CAAC,IAAA,qCAAgB,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACnE,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAjBW,QAAA,YAAY,gBAiBvB"}
|
||||
+11
-13
@@ -1,16 +1,14 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./constants"));
|
||||
__export(require("./error-message"));
|
||||
__export(require("./get-resources"));
|
||||
__export(require("./inject-resources"));
|
||||
__export(require("./load-resources"));
|
||||
__export(require("./match-files"));
|
||||
__export(require("./normalize-options"));
|
||||
__export(require("./resolve-import-url"));
|
||||
__export(require("./type-guards"));
|
||||
__export(require("./validate-options"));
|
||||
const tslib_1 = require("tslib");
|
||||
(0, tslib_1.__exportStar)(require("./constants"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./error-message"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./get-resources"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./inject-resources"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./load-resources"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./match-files"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./normalize-options"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./resolve-import-url"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./type-guards"), exports);
|
||||
(0, tslib_1.__exportStar)(require("./validate-options"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;AAAA,iCAA4B;AAC5B,qCAAgC;AAChC,qCAAgC;AAChC,wCAAmC;AACnC,sCAAiC;AACjC,mCAA8B;AAC9B,yCAAoC;AACpC,0CAAqC;AACrC,mCAA8B;AAC9B,wCAAmC"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,2DAA4B;AAC5B,+DAAgC;AAChC,+DAAgC;AAChC,kEAAmC;AACnC,gEAAiC;AACjC,6DAA8B;AAC9B,mEAAoC;AACpC,oEAAqC;AACrC,6DAA8B;AAC9B,kEAAmC"}
|
||||
+3
-2
@@ -1,2 +1,3 @@
|
||||
import { StyleResources, StyleResourcesLoaderNormalizedOptions } from '..';
|
||||
export declare const injectResources: (options: StyleResourcesLoaderNormalizedOptions, source: string, resources: StyleResources) => Promise<string>;
|
||||
import type { LoaderContext } from '../types';
|
||||
import type { StyleResources, StyleResourcesLoaderNormalizedOptions } from '..';
|
||||
export declare const injectResources: (ctx: LoaderContext, options: StyleResourcesLoaderNormalizedOptions, source: string, resources: StyleResources) => Promise<string>;
|
||||
|
||||
+7
-5
@@ -1,13 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = require(".");
|
||||
exports.injectResources = async (options, source, resources) => {
|
||||
exports.injectResources = void 0;
|
||||
const error_message_1 = require("./error-message");
|
||||
const injectResources = async (ctx, options, source, resources) => {
|
||||
const { injector } = options;
|
||||
const dist = injector(source, resources);
|
||||
const content = _1.isPromise(dist) ? await dist : dist;
|
||||
const dist = injector.call(ctx, source, resources);
|
||||
const content = await dist;
|
||||
if (typeof content !== 'string') {
|
||||
throw new Error(_1.errorMessage.invalidInjectorReturn);
|
||||
throw new Error(error_message_1.errorMessage.invalidInjectorReturn);
|
||||
}
|
||||
return content;
|
||||
};
|
||||
exports.injectResources = injectResources;
|
||||
//# sourceMappingURL=inject-resources.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"inject-resources.js","sourceRoot":"","sources":["../../src/utils/inject-resources.ts"],"names":[],"mappings":";;AAEA,wBAA0C;AAE7B,QAAA,eAAe,GAAG,KAAK,EAChC,OAA8C,EAC9C,MAAc,EACd,SAAyB,EAC3B,EAAE;IACA,MAAM,EAAC,QAAQ,EAAC,GAAG,OAAO,CAAC;IAE3B,MAAM,IAAI,GAAQ,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE9C,MAAM,OAAO,GAAG,YAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,eAAY,CAAC,qBAAqB,CAAC,CAAC;KACvD;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC"}
|
||||
{"version":3,"file":"inject-resources.js","sourceRoot":"","sources":["../../src/utils/inject-resources.ts"],"names":[],"mappings":";;;AAGA,mDAA6C;AAEtC,MAAM,eAAe,GAAG,KAAK,EAChC,GAAkB,EAClB,OAA8C,EAC9C,MAAc,EACd,SAAyB,EAC3B,EAAE;IACA,MAAM,EAAC,QAAQ,EAAC,GAAG,OAAO,CAAC;IAE3B,MAAM,IAAI,GAAY,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;IAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,4BAAY,CAAC,qBAAqB,CAAC,CAAC;KACvD;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
/// <reference types="webpack" />
|
||||
export declare const loadResources: (ctx: import("webpack").loader.LoaderContext, source: string, callback: import("webpack").loader.loaderCallback) => Promise<void>;
|
||||
import type { LoaderContext, LoaderCallback } from '../types';
|
||||
export declare const loadResources: (ctx: LoaderContext, source: string, callback: LoaderCallback) => Promise<void>;
|
||||
|
||||
+11
-7
@@ -1,15 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = require(".");
|
||||
exports.loadResources = async (ctx, source, callback) => {
|
||||
exports.loadResources = void 0;
|
||||
const get_resources_1 = require("./get-resources");
|
||||
const inject_resources_1 = require("./inject-resources");
|
||||
const normalize_options_1 = require("./normalize-options");
|
||||
const loadResources = async (ctx, source, callback) => {
|
||||
try {
|
||||
const options = _1.normalizeOptions(ctx);
|
||||
const resources = await _1.getResources(ctx, options);
|
||||
const content = await _1.injectResources(options, source, resources);
|
||||
return callback(null, content);
|
||||
const options = (0, normalize_options_1.normalizeOptions)(ctx);
|
||||
const resources = await (0, get_resources_1.getResources)(ctx, options);
|
||||
const content = await (0, inject_resources_1.injectResources)(ctx, options, source, resources);
|
||||
callback(null, content);
|
||||
}
|
||||
catch (err) {
|
||||
return callback(err);
|
||||
callback(err);
|
||||
}
|
||||
};
|
||||
exports.loadResources = loadResources;
|
||||
//# sourceMappingURL=load-resources.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"load-resources.js","sourceRoot":"","sources":["../../src/utils/load-resources.ts"],"names":[],"mappings":";;AAEA,wBAAkE;AAErD,QAAA,aAAa,GAAG,KAAK,EAAE,GAAkB,EAAE,MAAc,EAAE,QAAwB,EAAE,EAAE;IAChG,IAAI;QACA,MAAM,OAAO,GAAG,mBAAgB,CAAC,GAAG,CAAC,CAAC;QAEtC,MAAM,SAAS,GAAG,MAAM,eAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,OAAO,GAAG,MAAM,kBAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAElE,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KAClC;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;KACxB;AACL,CAAC,CAAC"}
|
||||
{"version":3,"file":"load-resources.js","sourceRoot":"","sources":["../../src/utils/load-resources.ts"],"names":[],"mappings":";;;AAEA,mDAA6C;AAC7C,yDAAmD;AACnD,2DAAqD;AAE9C,MAAM,aAAa,GAAG,KAAK,EAAE,GAAkB,EAAE,MAAc,EAAE,QAAwB,EAAE,EAAE;IAChG,IAAI;QACA,MAAM,OAAO,GAAG,IAAA,oCAAgB,EAAC,GAAG,CAAC,CAAC;QAEtC,MAAM,SAAS,GAAG,MAAM,IAAA,4BAAY,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,OAAO,GAAG,MAAM,IAAA,kCAAe,EAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAEvE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KAC3B;IAAC,OAAO,GAAY,EAAE;QACnB,QAAQ,CAAC,GAAY,CAAC,CAAC;KAC1B;AACL,CAAC,CAAC;AAZW,QAAA,aAAa,iBAYxB"}
|
||||
+2
-3
@@ -1,3 +1,2 @@
|
||||
/// <reference types="webpack" />
|
||||
import { StyleResourcesLoaderNormalizedOptions } from '..';
|
||||
export declare const matchFiles: (ctx: import("webpack").loader.LoaderContext, options: StyleResourcesLoaderNormalizedOptions) => Promise<string[]>;
|
||||
import type { LoaderContext, StyleResourcesLoaderNormalizedOptions } from '../types';
|
||||
export declare const matchFiles: (ctx: LoaderContext, options: StyleResourcesLoaderNormalizedOptions) => Promise<string[]>;
|
||||
|
||||
+9
-9
@@ -1,12 +1,11 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const util_1 = __importDefault(require("util"));
|
||||
const glob_1 = __importDefault(require("glob"));
|
||||
const _1 = require(".");
|
||||
exports.matchFiles = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
||||
const util_1 = (0, tslib_1.__importDefault)(require("util"));
|
||||
const glob_1 = (0, tslib_1.__importDefault)(require("glob"));
|
||||
const type_guards_1 = require("./type-guards");
|
||||
const isLegacyWebpack = (ctx) => !!ctx.options;
|
||||
const getRootContext = (ctx) => {
|
||||
if (isLegacyWebpack(ctx)) {
|
||||
@@ -18,14 +17,15 @@ const flatten = (items) => {
|
||||
const emptyItems = [];
|
||||
return emptyItems.concat(...items);
|
||||
};
|
||||
exports.matchFiles = async (ctx, options) => {
|
||||
const matchFiles = async (ctx, options) => {
|
||||
const { patterns, globOptions } = options;
|
||||
const files = await Promise.all(patterns.map(async (pattern) => {
|
||||
const rootContext = getRootContext(ctx);
|
||||
const absolutePattern = path_1.default.isAbsolute(pattern) ? pattern : path_1.default.resolve(rootContext, pattern);
|
||||
const partialFiles = await util_1.default.promisify(glob_1.default)(absolutePattern, globOptions);
|
||||
return partialFiles.filter(_1.isStyleFile);
|
||||
return partialFiles.filter(type_guards_1.isStyleFile);
|
||||
}));
|
||||
return [...new Set(flatten(files))].map(file => path_1.default.resolve(file));
|
||||
};
|
||||
exports.matchFiles = matchFiles;
|
||||
//# sourceMappingURL=match-files.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"match-files.js","sourceRoot":"","sources":["../../src/utils/match-files.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,gDAAwB;AAExB,gDAAwB;AAIxB,wBAA8B;AAE9B,MAAM,eAAe,GAAG,CAAC,GAAQ,EAAuC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;AAEzF,MAAM,cAAc,GAAG,CAAC,GAAkB,EAAE,EAAE;IAE1C,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;KAC9B;IAED,OAAO,GAAG,CAAC,WAAW,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAI,KAAY,EAAE,EAAE;IAChC,MAAM,UAAU,GAAQ,EAAE,CAAC;IAE3B,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;AACvC,CAAC,CAAC;AAEW,QAAA,UAAU,GAAG,KAAK,EAAE,GAAkB,EAAE,OAA8C,EAAE,EAAE;IACnG,MAAM,EAAC,QAAQ,EAAE,WAAW,EAAC,GAAG,OAAO,CAAC;IAExC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC3B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;QACzB,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,eAAe,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAChG,MAAM,YAAY,GAAG,MAAM,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAE9E,OAAO,YAAY,CAAC,MAAM,CAAC,cAAW,CAAC,CAAC;IAC5C,CAAC,CAAC,CACL,CAAC;IAQF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxE,CAAC,CAAC"}
|
||||
{"version":3,"file":"match-files.js","sourceRoot":"","sources":["../../src/utils/match-files.ts"],"names":[],"mappings":";;;;AAAA,6DAAwB;AACxB,6DAAwB;AAExB,6DAAwB;AAIxB,+CAA0C;AAG1C,MAAM,eAAe,GAAG,CAAC,GAAQ,EAAuC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;AAEzF,MAAM,cAAc,GAAG,CAAC,GAAkB,EAAE,EAAE;IAE1C,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;KAC9B;IAED,OAAO,GAAG,CAAC,WAAW,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAI,KAAY,EAAE,EAAE;IAChC,MAAM,UAAU,GAAQ,EAAE,CAAC;IAE3B,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;AACvC,CAAC,CAAC;AAEK,MAAM,UAAU,GAAG,KAAK,EAAE,GAAkB,EAAE,OAA8C,EAAE,EAAE;IACnG,MAAM,EAAC,QAAQ,EAAE,WAAW,EAAC,GAAG,OAAO,CAAC;IAExC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC3B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;QACzB,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,eAAe,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAChG,MAAM,YAAY,GAAG,MAAM,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAE9E,OAAO,YAAY,CAAC,MAAM,CAAC,yBAAW,CAAC,CAAC;IAC5C,CAAC,CAAC,CACL,CAAC;IAQF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxE,CAAC,CAAC;AApBW,QAAA,UAAU,cAoBrB"}
|
||||
+2
-3
@@ -1,3 +1,2 @@
|
||||
/// <reference types="webpack" />
|
||||
import { StyleResourcesLoaderNormalizedOptions } from '..';
|
||||
export declare const normalizeOptions: (ctx: import("webpack").loader.LoaderContext) => StyleResourcesLoaderNormalizedOptions;
|
||||
import type { LoaderContext, StyleResourcesLoaderNormalizedOptions } from '../types';
|
||||
export declare const normalizeOptions: (ctx: LoaderContext) => StyleResourcesLoaderNormalizedOptions;
|
||||
|
||||
+6
-4
@@ -1,8 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizeOptions = void 0;
|
||||
const os_1 = require("os");
|
||||
const loader_utils_1 = require("loader-utils");
|
||||
const _1 = require(".");
|
||||
const validate_options_1 = require("./validate-options");
|
||||
const normalizePatterns = (patterns) => Array.isArray(patterns) ? patterns : [patterns];
|
||||
const coerceContentEOL = (content) => (content.endsWith(os_1.EOL) ? content : `${content}${os_1.EOL}`);
|
||||
const getResourceContent = ({ content }) => coerceContentEOL(content);
|
||||
@@ -15,9 +16,9 @@ const normalizeInjector = (injector) => {
|
||||
}
|
||||
return injector;
|
||||
};
|
||||
exports.normalizeOptions = (ctx) => {
|
||||
const options = loader_utils_1.getOptions(ctx) || {};
|
||||
_1.validateOptions(options);
|
||||
const normalizeOptions = (ctx) => {
|
||||
const options = (0, loader_utils_1.getOptions)(ctx);
|
||||
(0, validate_options_1.validateOptions)(options);
|
||||
const { patterns, injector, globOptions = {}, resolveUrl = true } = options;
|
||||
return {
|
||||
patterns: normalizePatterns(patterns),
|
||||
@@ -26,4 +27,5 @@ exports.normalizeOptions = (ctx) => {
|
||||
resolveUrl,
|
||||
};
|
||||
};
|
||||
exports.normalizeOptions = normalizeOptions;
|
||||
//# sourceMappingURL=normalize-options.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"normalize-options.js","sourceRoot":"","sources":["../../src/utils/normalize-options.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,+CAAwC;AAUxC,wBAAkC;AAElC,MAAM,iBAAiB,GAAG,CAAC,QAAiD,EAAE,EAAE,CAC5E,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEpD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,QAAG,EAAE,CAAC,CAAC;AACrG,MAAM,kBAAkB,GAAG,CAAC,EAAC,OAAO,EAAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEnF,MAAM,iBAAiB,GAAG,CAAC,QAAiD,EAAoC,EAAE;IAC9G,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,SAAS,EAAE;QAC3D,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;KACrF;IAED,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACvB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACrF;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEW,QAAA,gBAAgB,GAAG,CAAC,GAAkB,EAAyC,EAAE;IAC1F,MAAM,OAAO,GAAG,yBAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAEtC,kBAAe,CAA8B,OAAO,CAAC,CAAC;IAEtD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,EAAE,UAAU,GAAG,IAAI,EAAC,GAAG,OAAO,CAAC;IAE1E,OAAO;QACH,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QACrC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QACrC,WAAW;QACX,UAAU;KACb,CAAC;AACN,CAAC,CAAC"}
|
||||
{"version":3,"file":"normalize-options.js","sourceRoot":"","sources":["../../src/utils/normalize-options.ts"],"names":[],"mappings":";;;AAAA,2BAAuB;AAEvB,+CAAwC;AAUxC,yDAAmD;AAEnD,MAAM,iBAAiB,GAAG,CAAC,QAAiD,EAAE,EAAE,CAC5E,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEpD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,QAAG,EAAE,CAAC,CAAC;AACrG,MAAM,kBAAkB,GAAG,CAAC,EAAC,OAAO,EAAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEnF,MAAM,iBAAiB,GAAG,CAAC,QAAiD,EAAoC,EAAE;IAC9G,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,SAAS,EAAE;QAC3D,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;KACrF;IAED,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACvB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACrF;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEK,MAAM,gBAAgB,GAAG,CAAC,GAAkB,EAAyC,EAAE;IAC1F,MAAM,OAAO,GAAG,IAAA,yBAAU,EAAC,GAAG,CAAC,CAAC;IAEhC,IAAA,kCAAe,EAA8B,OAAO,CAAC,CAAC;IAEtD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,EAAE,UAAU,GAAG,IAAI,EAAC,GAAG,OAAO,CAAC;IAE1E,OAAO;QACH,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QACrC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QACrC,WAAW;QACX,UAAU;KACb,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B"}
|
||||
+2
-3
@@ -1,3 +1,2 @@
|
||||
/// <reference types="webpack" />
|
||||
import { StyleResource } from '..';
|
||||
export declare const resolveImportUrl: (ctx: import("webpack").loader.LoaderContext, { file, content }: StyleResource) => StyleResource;
|
||||
import type { LoaderContext, StyleResource } from '../types';
|
||||
export declare const resolveImportUrl: (ctx: LoaderContext, { file, content }: StyleResource) => StyleResource;
|
||||
|
||||
+5
-5
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
exports.resolveImportUrl = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
||||
const regex = /@(?:import|require)\s+(?:\([a-z,\s]+\)\s*)?['"]?([^'"\s;]+)['"]?;?/gu;
|
||||
exports.resolveImportUrl = (ctx, { file, content }) => ({
|
||||
const resolveImportUrl = (ctx, { file, content }) => ({
|
||||
file,
|
||||
content: content.replace(regex, (match, pathToResource) => {
|
||||
if (!pathToResource || /^[~/]/u.test(pathToResource)) {
|
||||
@@ -19,4 +18,5 @@ exports.resolveImportUrl = (ctx, { file, content }) => ({
|
||||
return match.replace(pathToResource, relativePathFromContextToResource);
|
||||
}),
|
||||
});
|
||||
exports.resolveImportUrl = resolveImportUrl;
|
||||
//# sourceMappingURL=resolve-import-url.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"resolve-import-url.js","sourceRoot":"","sources":["../../src/utils/resolve-import-url.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAKxB,MAAM,KAAK,GAAG,sEAAsE,CAAC;AAExE,QAAA,gBAAgB,GAAG,CAAC,GAAkB,EAAE,EAAC,IAAI,EAAE,OAAO,EAAgB,EAAiB,EAAE,CAAC,CAAC;IACpG,IAAI;IACJ,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAa,EAAE,cAAuB,EAAE,EAAE;QACvE,IAAI,CAAC,cAAc,IAAI,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;YAClD,OAAO,KAAK,CAAC;SAChB;QAED,MAAM,sBAAsB,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC;QAChF,MAAM,iCAAiC,GAAG,cAAI;aACzC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,sBAAsB,CAAC;aAC7C,KAAK,CAAC,cAAI,CAAC,GAAG,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;QAEf,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,iCAAiC,CAAC,CAAC;IAC5E,CAAC,CAAC;CACL,CAAC,CAAC"}
|
||||
{"version":3,"file":"resolve-import-url.js","sourceRoot":"","sources":["../../src/utils/resolve-import-url.ts"],"names":[],"mappings":";;;;AAAA,6DAAwB;AAKxB,MAAM,KAAK,GAAG,sEAAsE,CAAC;AAE9E,MAAM,gBAAgB,GAAG,CAAC,GAAkB,EAAE,EAAC,IAAI,EAAE,OAAO,EAAgB,EAAiB,EAAE,CAAC,CAAC;IACpG,IAAI;IACJ,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAa,EAAE,cAAuB,EAAE,EAAE;QACvE,IAAI,CAAC,cAAc,IAAI,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;YAClD,OAAO,KAAK,CAAC;SAChB;QAED,MAAM,sBAAsB,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC;QAChF,MAAM,iCAAiC,GAAG,cAAI;aACzC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,sBAAsB,CAAC;aAC7C,KAAK,CAAC,cAAI,CAAC,GAAG,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;QAEf,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,iCAAiC,CAAC,CAAC;IAC5E,CAAC,CAAC;CACL,CAAC,CAAC;AAfU,QAAA,gBAAgB,oBAe1B"}
|
||||
-2
@@ -1,4 +1,2 @@
|
||||
import isPromise from 'is-promise';
|
||||
export declare const isFunction: <T extends (...args: any[]) => any>(arg: any) => arg is T;
|
||||
export declare const isStyleFile: (file: string) => boolean;
|
||||
export { isPromise };
|
||||
|
||||
+8
-9
@@ -1,12 +1,11 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const is_promise_1 = __importDefault(require("is-promise"));
|
||||
exports.isPromise = is_promise_1.default;
|
||||
const _1 = require(".");
|
||||
exports.isFunction = (arg) => typeof arg === 'function';
|
||||
exports.isStyleFile = (file) => _1.SUPPORTED_FILE_EXTS.includes(path_1.default.extname(file));
|
||||
exports.isStyleFile = exports.isFunction = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
||||
const constants_1 = require("./constants");
|
||||
const isFunction = (arg) => typeof arg === 'function';
|
||||
exports.isFunction = isFunction;
|
||||
const isStyleFile = (file) => constants_1.SUPPORTED_FILE_EXTS.includes(path_1.default.extname(file));
|
||||
exports.isStyleFile = isStyleFile;
|
||||
//# sourceMappingURL=type-guards.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAExB,4DAAmC;AAQ3B,oBARD,oBAAS,CAQC;AANjB,wBAAsC;AAEzB,QAAA,UAAU,GAAG,CAAoC,GAAQ,EAAY,EAAE,CAAC,OAAO,GAAG,KAAK,UAAU,CAAC;AAElG,QAAA,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,sBAAmB,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC"}
|
||||
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":";;;;AAAA,6DAAwB;AAExB,2CAAgD;AAEzC,MAAM,UAAU,GAAG,CAAoC,GAAQ,EAAY,EAAE,CAAC,OAAO,GAAG,KAAK,UAAU,CAAC;AAAlG,QAAA,UAAU,cAAwF;AAExG,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,+BAAmB,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAAjF,QAAA,WAAW,eAAsE"}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export declare const validateOptions: <T extends {}>(options: any) => asserts options is T;
|
||||
export declare const validateOptions: <T extends object>(options: object) => asserts options is T;
|
||||
|
||||
+9
-9
@@ -1,13 +1,13 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schema_utils_1 = __importDefault(require("schema-utils"));
|
||||
const __1 = require("..");
|
||||
const _1 = require(".");
|
||||
exports.validateOptions = options => schema_utils_1.default(__1.schema, options, {
|
||||
name: _1.LOADER_NAME,
|
||||
baseDataPath: _1.VALIDATION_BASE_DATA_PATH,
|
||||
exports.validateOptions = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const schema_utils_1 = (0, tslib_1.__importDefault)(require("schema-utils"));
|
||||
const schema_1 = require("../schema");
|
||||
const constants_1 = require("./constants");
|
||||
const validateOptions = options => (0, schema_utils_1.default)(schema_1.schema, options, {
|
||||
name: constants_1.LOADER_NAME,
|
||||
baseDataPath: constants_1.VALIDATION_BASE_DATA_PATH,
|
||||
});
|
||||
exports.validateOptions = validateOptions;
|
||||
//# sourceMappingURL=validate-options.js.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../../src/utils/validate-options.ts"],"names":[],"mappings":";;;;;AAAA,gEAAoC;AAEpC,0BAA0B;AAE1B,wBAAyD;AAE5C,QAAA,eAAe,GAAyD,OAAO,CAAC,EAAE,CAC3F,sBAAQ,CAAC,UAAM,EAAE,OAAO,EAAE;IACtB,IAAI,EAAE,cAAW;IACjB,YAAY,EAAE,4BAAyB;CAC1C,CAAC,CAAC"}
|
||||
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../../src/utils/validate-options.ts"],"names":[],"mappings":";;;;AAAA,6EAAoC;AAEpC,sCAAiC;AAEjC,2CAAmE;AAE5D,MAAM,eAAe,GAAgE,OAAO,CAAC,EAAE,CAClG,IAAA,sBAAQ,EAAC,eAAM,EAAE,OAAO,EAAE;IACtB,IAAI,EAAE,uBAAW;IACjB,YAAY,EAAE,qCAAyB;CAC1C,CAAC,CAAC;AAJM,QAAA,eAAe,mBAIrB"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
Copyright JS Foundation and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
# loader-utils
|
||||
|
||||
## Methods
|
||||
|
||||
### `getOptions`
|
||||
|
||||
Recommended way to retrieve the options of a loader invocation:
|
||||
|
||||
```javascript
|
||||
// inside your loader
|
||||
const options = loaderUtils.getOptions(this);
|
||||
```
|
||||
|
||||
1. If `this.query` is a string:
|
||||
- Tries to parse the query string and returns a new object
|
||||
- Throws if it's not a valid query string
|
||||
2. If `this.query` is object-like, it just returns `this.query`
|
||||
3. In any other case, it just returns `null`
|
||||
|
||||
**Please note:** The returned `options` object is *read-only*. It may be re-used across multiple invocations.
|
||||
If you pass it on to another library, make sure to make a *deep copy* of it:
|
||||
|
||||
```javascript
|
||||
const options = Object.assign(
|
||||
{},
|
||||
defaultOptions,
|
||||
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
|
||||
);
|
||||
// don't forget nested objects or arrays
|
||||
options.obj = Object.assign({}, options.obj);
|
||||
options.arr = options.arr.slice();
|
||||
someLibrary(options);
|
||||
```
|
||||
|
||||
[clone](https://www.npmjs.com/package/clone) is a good library to make a deep copy of the options.
|
||||
|
||||
#### Options as query strings
|
||||
|
||||
If the loader options have been passed as loader query string (`loader?some¶ms`), the string is parsed by using [`parseQuery`](#parsequery).
|
||||
|
||||
### `parseQuery`
|
||||
|
||||
Parses a passed string (e.g. `loaderContext.resourceQuery`) as a query string, and returns an object.
|
||||
|
||||
``` javascript
|
||||
const params = loaderUtils.parseQuery(this.resourceQuery); // resource: `file?param1=foo`
|
||||
if (params.param1 === "foo") {
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
The string is parsed like this:
|
||||
|
||||
``` text
|
||||
-> Error
|
||||
? -> {}
|
||||
?flag -> { flag: true }
|
||||
?+flag -> { flag: true }
|
||||
?-flag -> { flag: false }
|
||||
?xyz=test -> { xyz: "test" }
|
||||
?xyz=1 -> { xyz: "1" } // numbers are NOT parsed
|
||||
?xyz[]=a -> { xyz: ["a"] }
|
||||
?flag1&flag2 -> { flag1: true, flag2: true }
|
||||
?+flag1,-flag2 -> { flag1: true, flag2: false }
|
||||
?xyz[]=a,xyz[]=b -> { xyz: ["a", "b"] }
|
||||
?a%2C%26b=c%2C%26d -> { "a,&b": "c,&d" }
|
||||
?{data:{a:1},isJSON5:true} -> { data: { a: 1 }, isJSON5: true }
|
||||
```
|
||||
|
||||
### `stringifyRequest`
|
||||
|
||||
Turns a request into a string that can be used inside `require()` or `import` while avoiding absolute paths.
|
||||
Use it instead of `JSON.stringify(...)` if you're generating code inside a loader.
|
||||
|
||||
**Why is this necessary?** Since webpack calculates the hash before module paths are translated into module ids, we must avoid absolute paths to ensure
|
||||
consistent hashes across different compilations.
|
||||
|
||||
This function:
|
||||
|
||||
- resolves absolute requests into relative requests if the request and the module are on the same hard drive
|
||||
- replaces `\` with `/` if the request and the module are on the same hard drive
|
||||
- won't change the path at all if the request and the module are on different hard drives
|
||||
- applies `JSON.stringify` to the result
|
||||
|
||||
```javascript
|
||||
loaderUtils.stringifyRequest(this, "./test.js");
|
||||
// "\"./test.js\""
|
||||
|
||||
loaderUtils.stringifyRequest(this, ".\\test.js");
|
||||
// "\"./test.js\""
|
||||
|
||||
loaderUtils.stringifyRequest(this, "test");
|
||||
// "\"test\""
|
||||
|
||||
loaderUtils.stringifyRequest(this, "test/lib/index.js");
|
||||
// "\"test/lib/index.js\""
|
||||
|
||||
loaderUtils.stringifyRequest(this, "otherLoader?andConfig!test?someConfig");
|
||||
// "\"otherLoader?andConfig!test?someConfig\""
|
||||
|
||||
loaderUtils.stringifyRequest(this, require.resolve("test"));
|
||||
// "\"../node_modules/some-loader/lib/test.js\""
|
||||
|
||||
loaderUtils.stringifyRequest(this, "C:\\module\\test.js");
|
||||
// "\"../../test.js\"" (on Windows, in case the module and the request are on the same drive)
|
||||
|
||||
loaderUtils.stringifyRequest(this, "C:\\module\\test.js");
|
||||
// "\"C:\\module\\test.js\"" (on Windows, in case the module and the request are on different drives)
|
||||
|
||||
loaderUtils.stringifyRequest(this, "\\\\network-drive\\test.js");
|
||||
// "\"\\\\network-drive\\\\test.js\"" (on Windows, in case the module and the request are on different drives)
|
||||
```
|
||||
|
||||
### `urlToRequest`
|
||||
|
||||
Converts some resource URL to a webpack module request.
|
||||
|
||||
> i Before call `urlToRequest` you need call `isUrlRequest` to ensure it is requestable url
|
||||
|
||||
```javascript
|
||||
const url = "path/to/module.js";
|
||||
|
||||
if (loaderUtils.isUrlRequest(url)) {
|
||||
// Logic for requestable url
|
||||
const request = loaderUtils.urlToRequest(url);
|
||||
} else {
|
||||
// Logic for not requestable url
|
||||
}
|
||||
```
|
||||
|
||||
Simple example:
|
||||
|
||||
```javascript
|
||||
const url = "path/to/module.js";
|
||||
const request = loaderUtils.urlToRequest(url); // "./path/to/module.js"
|
||||
```
|
||||
|
||||
#### Module URLs
|
||||
|
||||
Any URL containing a `~` will be interpreted as a module request. Anything after the `~` will be considered the request path.
|
||||
|
||||
```javascript
|
||||
const url = "~path/to/module.js";
|
||||
const request = loaderUtils.urlToRequest(url); // "path/to/module.js"
|
||||
```
|
||||
|
||||
#### Root-relative URLs
|
||||
|
||||
URLs that are root-relative (start with `/`) can be resolved relative to some arbitrary path by using the `root` parameter:
|
||||
|
||||
```javascript
|
||||
const url = "/path/to/module.js";
|
||||
const root = "./root";
|
||||
const request = loaderUtils.urlToRequest(url, root); // "./root/path/to/module.js"
|
||||
```
|
||||
|
||||
To convert a root-relative URL into a module URL, specify a `root` value that starts with `~`:
|
||||
|
||||
```javascript
|
||||
const url = "/path/to/module.js";
|
||||
const root = "~";
|
||||
const request = loaderUtils.urlToRequest(url, root); // "path/to/module.js"
|
||||
```
|
||||
|
||||
### `interpolateName`
|
||||
|
||||
Interpolates a filename template using multiple placeholders and/or a regular expression.
|
||||
The template and regular expression are set as query params called `name` and `regExp` on the current loader's context.
|
||||
|
||||
```javascript
|
||||
const interpolatedName = loaderUtils.interpolateName(loaderContext, name, options);
|
||||
```
|
||||
|
||||
The following tokens are replaced in the `name` parameter:
|
||||
|
||||
* `[ext]` the extension of the resource
|
||||
* `[name]` the basename of the resource
|
||||
* `[path]` the path of the resource relative to the `context` query parameter or option.
|
||||
* `[folder]` the folder the resource is in
|
||||
* `[query]` the queryof the resource, i.e. `?foo=bar`
|
||||
* `[emoji]` a random emoji representation of `options.content`
|
||||
* `[emoji:<length>]` same as above, but with a customizable number of emojis
|
||||
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
|
||||
* `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
|
||||
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
|
||||
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
|
||||
* and `length` the length in chars
|
||||
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
|
||||
* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
|
||||
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
|
||||
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
|
||||
* and `length` the length in chars
|
||||
* `[N]` the N-th match obtained from matching the current file name against `options.regExp`
|
||||
|
||||
In loader context `[hash]` and `[contenthash]` are the same, but we recommend using `[contenthash]` for avoid misleading.
|
||||
|
||||
Examples
|
||||
|
||||
``` javascript
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
|
||||
loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext]", { content: ... });
|
||||
// => js/9473fdd0d880a43c21b7778d34872157.script.js
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
|
||||
// loaderContext.resourceQuery = "?foo=bar"
|
||||
loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext][query]", { content: ... });
|
||||
// => js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
|
||||
loaderUtils.interpolateName(loaderContext, "js/[contenthash].script.[ext]", { content: ... });
|
||||
// => js/9473fdd0d880a43c21b7778d34872157.script.js
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/page.html"
|
||||
loaderUtils.interpolateName(loaderContext, "html-[hash:6].html", { content: ... });
|
||||
// => html-9473fd.html
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/flash.txt"
|
||||
loaderUtils.interpolateName(loaderContext, "[hash]", { content: ... });
|
||||
// => c31e9820c001c9c4a86bce33ce43b679
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.gif"
|
||||
loaderUtils.interpolateName(loaderContext, "[emoji]", { content: ... });
|
||||
// => 👍
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.gif"
|
||||
loaderUtils.interpolateName(loaderContext, "[emoji:4]", { content: ... });
|
||||
// => 🙍🏢📤🐝
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.png"
|
||||
loaderUtils.interpolateName(loaderContext, "[sha512:hash:base64:7].[ext]", { content: ... });
|
||||
// => 2BKDTjl.png
|
||||
// use sha512 hash instead of md4 and with only 7 chars of base64
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/img/myself.png"
|
||||
// loaderContext.query.name =
|
||||
loaderUtils.interpolateName(loaderContext, "picture.png");
|
||||
// => picture.png
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/dir/file.png"
|
||||
loaderUtils.interpolateName(loaderContext, "[path][name].[ext]?[hash]", { content: ... });
|
||||
// => /app/dir/file.png?9473fdd0d880a43c21b7778d34872157
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/js/page-home.js"
|
||||
loaderUtils.interpolateName(loaderContext, "script-[1].[ext]", { regExp: "page-(.*)\\.js", content: ... });
|
||||
// => script-home.js
|
||||
|
||||
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
|
||||
// loaderContext.resourceQuery = "?foo=bar"
|
||||
loaderUtils.interpolateName(
|
||||
loaderContext,
|
||||
(resourcePath, resourceQuery) => {
|
||||
// resourcePath - `/app/js/javascript.js`
|
||||
// resourceQuery - `?foo=bar`
|
||||
|
||||
return "js/[hash].script.[ext]";
|
||||
},
|
||||
{ content: ... }
|
||||
);
|
||||
// => js/9473fdd0d880a43c21b7778d34872157.script.js
|
||||
```
|
||||
|
||||
### `getHashDigest`
|
||||
|
||||
``` javascript
|
||||
const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, maxLength);
|
||||
```
|
||||
|
||||
* `buffer` the content that should be hashed
|
||||
* `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
|
||||
* `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
|
||||
* `maxLength` the maximum length in chars
|
||||
|
||||
## License
|
||||
|
||||
MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
function getCurrentRequest(loaderContext) {
|
||||
if (loaderContext.currentRequest) {
|
||||
return loaderContext.currentRequest;
|
||||
}
|
||||
|
||||
const request = loaderContext.loaders
|
||||
.slice(loaderContext.loaderIndex)
|
||||
.map((obj) => obj.request)
|
||||
.concat([loaderContext.resource]);
|
||||
|
||||
return request.join('!');
|
||||
}
|
||||
|
||||
module.exports = getCurrentRequest;
|
||||
Generated
Vendored
+91
@@ -0,0 +1,91 @@
|
||||
'use strict';
|
||||
|
||||
const baseEncodeTables = {
|
||||
26: 'abcdefghijklmnopqrstuvwxyz',
|
||||
32: '123456789abcdefghjkmnpqrstuvwxyz', // no 0lio
|
||||
36: '0123456789abcdefghijklmnopqrstuvwxyz',
|
||||
49: 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', // no lIO
|
||||
52: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
58: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', // no 0lIO
|
||||
62: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
64: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_',
|
||||
};
|
||||
|
||||
function encodeBufferToBase(buffer, base) {
|
||||
const encodeTable = baseEncodeTables[base];
|
||||
if (!encodeTable) {
|
||||
throw new Error('Unknown encoding base' + base);
|
||||
}
|
||||
|
||||
const readLength = buffer.length;
|
||||
const Big = require('big.js');
|
||||
|
||||
Big.RM = Big.DP = 0;
|
||||
let b = new Big(0);
|
||||
|
||||
for (let i = readLength - 1; i >= 0; i--) {
|
||||
b = b.times(256).plus(buffer[i]);
|
||||
}
|
||||
|
||||
let output = '';
|
||||
while (b.gt(0)) {
|
||||
output = encodeTable[b.mod(base)] + output;
|
||||
b = b.div(base);
|
||||
}
|
||||
|
||||
Big.DP = 20;
|
||||
Big.RM = 1;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
let createMd4 = undefined;
|
||||
let BatchedHash = undefined;
|
||||
|
||||
function getHashDigest(buffer, hashType, digestType, maxLength) {
|
||||
hashType = hashType || 'md4';
|
||||
maxLength = maxLength || 9999;
|
||||
|
||||
let hash;
|
||||
|
||||
try {
|
||||
hash = require('crypto').createHash(hashType);
|
||||
} catch (error) {
|
||||
if (error.code === 'ERR_OSSL_EVP_UNSUPPORTED' && hashType === 'md4') {
|
||||
if (createMd4 === undefined) {
|
||||
createMd4 = require('./hash/md4');
|
||||
|
||||
if (BatchedHash === undefined) {
|
||||
BatchedHash = require('./hash/BatchedHash');
|
||||
}
|
||||
}
|
||||
|
||||
hash = new BatchedHash(createMd4());
|
||||
}
|
||||
|
||||
if (!hash) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
hash.update(buffer);
|
||||
|
||||
if (
|
||||
digestType === 'base26' ||
|
||||
digestType === 'base32' ||
|
||||
digestType === 'base36' ||
|
||||
digestType === 'base49' ||
|
||||
digestType === 'base52' ||
|
||||
digestType === 'base58' ||
|
||||
digestType === 'base62'
|
||||
) {
|
||||
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(
|
||||
0,
|
||||
maxLength
|
||||
);
|
||||
} else {
|
||||
return hash.digest(digestType || 'hex').substr(0, maxLength);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = getHashDigest;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const parseQuery = require('./parseQuery');
|
||||
|
||||
function getOptions(loaderContext) {
|
||||
const query = loaderContext.query;
|
||||
|
||||
if (typeof query === 'string' && query !== '') {
|
||||
return parseQuery(loaderContext.query);
|
||||
}
|
||||
|
||||
if (!query || typeof query !== 'object') {
|
||||
// Not object-like queries are not supported.
|
||||
return {};
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
module.exports = getOptions;
|
||||
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
function getRemainingRequest(loaderContext) {
|
||||
if (loaderContext.remainingRequest) {
|
||||
return loaderContext.remainingRequest;
|
||||
}
|
||||
|
||||
const request = loaderContext.loaders
|
||||
.slice(loaderContext.loaderIndex + 1)
|
||||
.map((obj) => obj.request)
|
||||
.concat([loaderContext.resource]);
|
||||
|
||||
return request.join('!');
|
||||
}
|
||||
|
||||
module.exports = getRemainingRequest;
|
||||
Generated
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
const MAX_SHORT_STRING = require('./wasm-hash').MAX_SHORT_STRING;
|
||||
|
||||
class BatchedHash {
|
||||
constructor(hash) {
|
||||
this.string = undefined;
|
||||
this.encoding = undefined;
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
||||
* @param {string|Buffer} data data
|
||||
* @param {string=} inputEncoding data encoding
|
||||
* @returns {this} updated hash
|
||||
*/
|
||||
update(data, inputEncoding) {
|
||||
if (this.string !== undefined) {
|
||||
if (
|
||||
typeof data === 'string' &&
|
||||
inputEncoding === this.encoding &&
|
||||
this.string.length + data.length < MAX_SHORT_STRING
|
||||
) {
|
||||
this.string += data;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
this.hash.update(this.string, this.encoding);
|
||||
this.string = undefined;
|
||||
}
|
||||
|
||||
if (typeof data === 'string') {
|
||||
if (
|
||||
data.length < MAX_SHORT_STRING &&
|
||||
// base64 encoding is not valid since it may contain padding chars
|
||||
(!inputEncoding || !inputEncoding.startsWith('ba'))
|
||||
) {
|
||||
this.string = data;
|
||||
this.encoding = inputEncoding;
|
||||
} else {
|
||||
this.hash.update(data, inputEncoding);
|
||||
}
|
||||
} else {
|
||||
this.hash.update(data);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
||||
* @param {string=} encoding encoding of the return value
|
||||
* @returns {string|Buffer} digest
|
||||
*/
|
||||
digest(encoding) {
|
||||
if (this.string !== undefined) {
|
||||
this.hash.update(this.string, this.encoding);
|
||||
}
|
||||
|
||||
return this.hash.digest(encoding);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BatchedHash;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const create = require('./wasm-hash');
|
||||
|
||||
//#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
|
||||
const md4 = new WebAssembly.Module(
|
||||
Buffer.from(
|
||||
// 2150 bytes
|
||||
'AGFzbQEAAAABCAJgAX8AYAAAAwUEAQAAAAUDAQABBhoFfwFBAAt/AUEAC38BQQALfwFBAAt/AUEACwciBARpbml0AAAGdXBkYXRlAAIFZmluYWwAAwZtZW1vcnkCAAqFEAQmAEGBxpS6BiQBQYnXtv5+JAJB/rnrxXkkA0H2qMmBASQEQQAkAAvMCgEYfyMBIQojAiEGIwMhByMEIQgDQCAAIAVLBEAgBSgCCCINIAcgBiAFKAIEIgsgCCAHIAUoAgAiDCAKIAggBiAHIAhzcXNqakEDdyIDIAYgB3Nxc2pqQQd3IgEgAyAGc3FzampBC3chAiAFKAIUIg8gASACIAUoAhAiCSADIAEgBSgCDCIOIAYgAyACIAEgA3Nxc2pqQRN3IgQgASACc3FzampBA3ciAyACIARzcXNqakEHdyEBIAUoAiAiEiADIAEgBSgCHCIRIAQgAyAFKAIYIhAgAiAEIAEgAyAEc3FzampBC3ciAiABIANzcXNqakETdyIEIAEgAnNxc2pqQQN3IQMgBSgCLCIVIAQgAyAFKAIoIhQgAiAEIAUoAiQiEyABIAIgAyACIARzcXNqakEHdyIBIAMgBHNxc2pqQQt3IgIgASADc3FzampBE3chBCAPIBAgCSAVIBQgEyAFKAI4IhYgAiAEIAUoAjQiFyABIAIgBSgCMCIYIAMgASAEIAEgAnNxc2pqQQN3IgEgAiAEc3FzampBB3ciAiABIARzcXNqakELdyIDIAkgAiAMIAEgBSgCPCIJIAQgASADIAEgAnNxc2pqQRN3IgEgAiADcnEgAiADcXJqakGZ84nUBWpBA3ciAiABIANycSABIANxcmpqQZnzidQFakEFdyIEIAEgAnJxIAEgAnFyaiASakGZ84nUBWpBCXciAyAPIAQgCyACIBggASADIAIgBHJxIAIgBHFyampBmfOJ1AVqQQ13IgEgAyAEcnEgAyAEcXJqakGZ84nUBWpBA3ciAiABIANycSABIANxcmpqQZnzidQFakEFdyIEIAEgAnJxIAEgAnFyampBmfOJ1AVqQQl3IgMgECAEIAIgFyABIAMgAiAEcnEgAiAEcXJqakGZ84nUBWpBDXciASADIARycSADIARxcmogDWpBmfOJ1AVqQQN3IgIgASADcnEgASADcXJqakGZ84nUBWpBBXciBCABIAJycSABIAJxcmpqQZnzidQFakEJdyIDIBEgBCAOIAIgFiABIAMgAiAEcnEgAiAEcXJqakGZ84nUBWpBDXciASADIARycSADIARxcmpqQZnzidQFakEDdyICIAEgA3JxIAEgA3FyampBmfOJ1AVqQQV3IgQgASACcnEgASACcXJqakGZ84nUBWpBCXciAyAMIAIgAyAJIAEgAyACIARycSACIARxcmpqQZnzidQFakENdyIBcyAEc2pqQaHX5/YGakEDdyICIAQgASACcyADc2ogEmpBodfn9gZqQQl3IgRzIAFzampBodfn9gZqQQt3IgMgAiADIBggASADIARzIAJzampBodfn9gZqQQ93IgFzIARzaiANakGh1+f2BmpBA3ciAiAUIAQgASACcyADc2pqQaHX5/YGakEJdyIEcyABc2pqQaHX5/YGakELdyIDIAsgAiADIBYgASADIARzIAJzampBodfn9gZqQQ93IgFzIARzampBodfn9gZqQQN3IgIgEyAEIAEgAnMgA3NqakGh1+f2BmpBCXciBHMgAXNqakGh1+f2BmpBC3chAyAKIA4gAiADIBcgASADIARzIAJzampBodfn9gZqQQ93IgFzIARzampBodfn9gZqQQN3IgJqIQogBiAJIAEgESADIAIgFSAEIAEgAnMgA3NqakGh1+f2BmpBCXciBHMgAXNqakGh1+f2BmpBC3ciAyAEcyACc2pqQaHX5/YGakEPd2ohBiADIAdqIQcgBCAIaiEIIAVBQGshBQwBCwsgCiQBIAYkAiAHJAMgCCQECw0AIAAQASMAIABqJAAL/wQCA38BfiMAIABqrUIDhiEEIABByABqQUBxIgJBCGshAyAAIgFBAWohACABQYABOgAAA0AgACACSUEAIABBB3EbBEAgAEEAOgAAIABBAWohAAwBCwsDQCAAIAJJBEAgAEIANwMAIABBCGohAAwBCwsgAyAENwMAIAIQAUEAIwGtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEIIwKtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEQIwOtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEYIwStIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAAs=',
|
||||
'base64'
|
||||
)
|
||||
);
|
||||
//#endregion
|
||||
|
||||
module.exports = create.bind(null, md4, [], 64, 32);
|
||||
Generated
Vendored
+208
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// 65536 is the size of a wasm memory page
|
||||
// 64 is the maximum chunk size for every possible wasm hash implementation
|
||||
// 4 is the maximum number of bytes per char for string encoding (max is utf-8)
|
||||
// ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
|
||||
const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
|
||||
|
||||
class WasmHash {
|
||||
/**
|
||||
* @param {WebAssembly.Instance} instance wasm instance
|
||||
* @param {WebAssembly.Instance[]} instancesPool pool of instances
|
||||
* @param {number} chunkSize size of data chunks passed to wasm
|
||||
* @param {number} digestSize size of digest returned by wasm
|
||||
*/
|
||||
constructor(instance, instancesPool, chunkSize, digestSize) {
|
||||
const exports = /** @type {any} */ (instance.exports);
|
||||
|
||||
exports.init();
|
||||
|
||||
this.exports = exports;
|
||||
this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
|
||||
this.buffered = 0;
|
||||
this.instancesPool = instancesPool;
|
||||
this.chunkSize = chunkSize;
|
||||
this.digestSize = digestSize;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.buffered = 0;
|
||||
this.exports.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Buffer | string} data data
|
||||
* @param {BufferEncoding=} encoding encoding
|
||||
* @returns {this} itself
|
||||
*/
|
||||
update(data, encoding) {
|
||||
if (typeof data === 'string') {
|
||||
while (data.length > MAX_SHORT_STRING) {
|
||||
this._updateWithShortString(data.slice(0, MAX_SHORT_STRING), encoding);
|
||||
data = data.slice(MAX_SHORT_STRING);
|
||||
}
|
||||
|
||||
this._updateWithShortString(data, encoding);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
this._updateWithBuffer(data);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} data data
|
||||
* @param {BufferEncoding=} encoding encoding
|
||||
* @returns {void}
|
||||
*/
|
||||
_updateWithShortString(data, encoding) {
|
||||
const { exports, buffered, mem, chunkSize } = this;
|
||||
|
||||
let endPos;
|
||||
|
||||
if (data.length < 70) {
|
||||
if (!encoding || encoding === 'utf-8' || encoding === 'utf8') {
|
||||
endPos = buffered;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const cc = data.charCodeAt(i);
|
||||
|
||||
if (cc < 0x80) {
|
||||
mem[endPos++] = cc;
|
||||
} else if (cc < 0x800) {
|
||||
mem[endPos] = (cc >> 6) | 0xc0;
|
||||
mem[endPos + 1] = (cc & 0x3f) | 0x80;
|
||||
endPos += 2;
|
||||
} else {
|
||||
// bail-out for weird chars
|
||||
endPos += mem.write(data.slice(i), endPos, encoding);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (encoding === 'latin1') {
|
||||
endPos = buffered;
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const cc = data.charCodeAt(i);
|
||||
|
||||
mem[endPos++] = cc;
|
||||
}
|
||||
} else {
|
||||
endPos = buffered + mem.write(data, buffered, encoding);
|
||||
}
|
||||
} else {
|
||||
endPos = buffered + mem.write(data, buffered, encoding);
|
||||
}
|
||||
|
||||
if (endPos < chunkSize) {
|
||||
this.buffered = endPos;
|
||||
} else {
|
||||
const l = endPos & ~(this.chunkSize - 1);
|
||||
|
||||
exports.update(l);
|
||||
|
||||
const newBuffered = endPos - l;
|
||||
|
||||
this.buffered = newBuffered;
|
||||
|
||||
if (newBuffered > 0) {
|
||||
mem.copyWithin(0, l, endPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Buffer} data data
|
||||
* @returns {void}
|
||||
*/
|
||||
_updateWithBuffer(data) {
|
||||
const { exports, buffered, mem } = this;
|
||||
const length = data.length;
|
||||
|
||||
if (buffered + length < this.chunkSize) {
|
||||
data.copy(mem, buffered, 0, length);
|
||||
|
||||
this.buffered += length;
|
||||
} else {
|
||||
const l = (buffered + length) & ~(this.chunkSize - 1);
|
||||
|
||||
if (l > 65536) {
|
||||
let i = 65536 - buffered;
|
||||
|
||||
data.copy(mem, buffered, 0, i);
|
||||
exports.update(65536);
|
||||
|
||||
const stop = l - buffered - 65536;
|
||||
|
||||
while (i < stop) {
|
||||
data.copy(mem, 0, i, i + 65536);
|
||||
exports.update(65536);
|
||||
i += 65536;
|
||||
}
|
||||
|
||||
data.copy(mem, 0, i, l - buffered);
|
||||
|
||||
exports.update(l - buffered - i);
|
||||
} else {
|
||||
data.copy(mem, buffered, 0, l - buffered);
|
||||
|
||||
exports.update(l);
|
||||
}
|
||||
|
||||
const newBuffered = length + buffered - l;
|
||||
|
||||
this.buffered = newBuffered;
|
||||
|
||||
if (newBuffered > 0) {
|
||||
data.copy(mem, 0, length - newBuffered, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
digest(type) {
|
||||
const { exports, buffered, mem, digestSize } = this;
|
||||
|
||||
exports.final(buffered);
|
||||
|
||||
this.instancesPool.push(this);
|
||||
|
||||
const hex = mem.toString('latin1', 0, digestSize);
|
||||
|
||||
if (type === 'hex') {
|
||||
return hex;
|
||||
}
|
||||
|
||||
if (type === 'binary' || !type) {
|
||||
return Buffer.from(hex, 'hex');
|
||||
}
|
||||
|
||||
return Buffer.from(hex, 'hex').toString(type);
|
||||
}
|
||||
}
|
||||
|
||||
const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
|
||||
if (instancesPool.length > 0) {
|
||||
const old = instancesPool.pop();
|
||||
|
||||
old.reset();
|
||||
|
||||
return old;
|
||||
} else {
|
||||
return new WasmHash(
|
||||
new WebAssembly.Instance(wasmModule),
|
||||
instancesPool,
|
||||
chunkSize,
|
||||
digestSize
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = create;
|
||||
module.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const getOptions = require('./getOptions');
|
||||
const parseQuery = require('./parseQuery');
|
||||
const stringifyRequest = require('./stringifyRequest');
|
||||
const getRemainingRequest = require('./getRemainingRequest');
|
||||
const getCurrentRequest = require('./getCurrentRequest');
|
||||
const isUrlRequest = require('./isUrlRequest');
|
||||
const urlToRequest = require('./urlToRequest');
|
||||
const parseString = require('./parseString');
|
||||
const getHashDigest = require('./getHashDigest');
|
||||
const interpolateName = require('./interpolateName');
|
||||
|
||||
exports.getOptions = getOptions;
|
||||
exports.parseQuery = parseQuery;
|
||||
exports.stringifyRequest = stringifyRequest;
|
||||
exports.getRemainingRequest = getRemainingRequest;
|
||||
exports.getCurrentRequest = getCurrentRequest;
|
||||
exports.isUrlRequest = isUrlRequest;
|
||||
exports.urlToRequest = urlToRequest;
|
||||
exports.parseString = parseString;
|
||||
exports.getHashDigest = getHashDigest;
|
||||
exports.interpolateName = interpolateName;
|
||||
Generated
Vendored
+151
@@ -0,0 +1,151 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const emojisList = require('emojis-list');
|
||||
const getHashDigest = require('./getHashDigest');
|
||||
|
||||
const emojiRegex = /[\uD800-\uDFFF]./;
|
||||
const emojiList = emojisList.filter((emoji) => emojiRegex.test(emoji));
|
||||
const emojiCache = {};
|
||||
|
||||
function encodeStringToEmoji(content, length) {
|
||||
if (emojiCache[content]) {
|
||||
return emojiCache[content];
|
||||
}
|
||||
|
||||
length = length || 1;
|
||||
|
||||
const emojis = [];
|
||||
|
||||
do {
|
||||
if (!emojiList.length) {
|
||||
throw new Error('Ran out of emoji');
|
||||
}
|
||||
|
||||
const index = Math.floor(Math.random() * emojiList.length);
|
||||
|
||||
emojis.push(emojiList[index]);
|
||||
emojiList.splice(index, 1);
|
||||
} while (--length > 0);
|
||||
|
||||
const emojiEncoding = emojis.join('');
|
||||
|
||||
emojiCache[content] = emojiEncoding;
|
||||
|
||||
return emojiEncoding;
|
||||
}
|
||||
|
||||
function interpolateName(loaderContext, name, options) {
|
||||
let filename;
|
||||
|
||||
const hasQuery =
|
||||
loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1;
|
||||
|
||||
if (typeof name === 'function') {
|
||||
filename = name(
|
||||
loaderContext.resourcePath,
|
||||
hasQuery ? loaderContext.resourceQuery : undefined
|
||||
);
|
||||
} else {
|
||||
filename = name || '[hash].[ext]';
|
||||
}
|
||||
|
||||
const context = options.context;
|
||||
const content = options.content;
|
||||
const regExp = options.regExp;
|
||||
|
||||
let ext = 'bin';
|
||||
let basename = 'file';
|
||||
let directory = '';
|
||||
let folder = '';
|
||||
let query = '';
|
||||
|
||||
if (loaderContext.resourcePath) {
|
||||
const parsed = path.parse(loaderContext.resourcePath);
|
||||
let resourcePath = loaderContext.resourcePath;
|
||||
|
||||
if (parsed.ext) {
|
||||
ext = parsed.ext.substr(1);
|
||||
}
|
||||
|
||||
if (parsed.dir) {
|
||||
basename = parsed.name;
|
||||
resourcePath = parsed.dir + path.sep;
|
||||
}
|
||||
|
||||
if (typeof context !== 'undefined') {
|
||||
directory = path
|
||||
.relative(context, resourcePath + '_')
|
||||
.replace(/\\/g, '/')
|
||||
.replace(/\.\.(\/)?/g, '_$1');
|
||||
directory = directory.substr(0, directory.length - 1);
|
||||
} else {
|
||||
directory = resourcePath.replace(/\\/g, '/').replace(/\.\.(\/)?/g, '_$1');
|
||||
}
|
||||
|
||||
if (directory.length === 1) {
|
||||
directory = '';
|
||||
} else if (directory.length > 1) {
|
||||
folder = path.basename(directory);
|
||||
}
|
||||
}
|
||||
|
||||
if (loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1) {
|
||||
query = loaderContext.resourceQuery;
|
||||
|
||||
const hashIdx = query.indexOf('#');
|
||||
|
||||
if (hashIdx >= 0) {
|
||||
query = query.substr(0, hashIdx);
|
||||
}
|
||||
}
|
||||
|
||||
let url = filename;
|
||||
|
||||
if (content) {
|
||||
// Match hash template
|
||||
url = url
|
||||
// `hash` and `contenthash` are same in `loader-utils` context
|
||||
// let's keep `hash` for backward compatibility
|
||||
.replace(
|
||||
/\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi,
|
||||
(all, hashType, digestType, maxLength) =>
|
||||
getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
|
||||
)
|
||||
.replace(/\[emoji(?::(\d+))?\]/gi, (all, length) =>
|
||||
encodeStringToEmoji(content, parseInt(length, 10))
|
||||
);
|
||||
}
|
||||
|
||||
url = url
|
||||
.replace(/\[ext\]/gi, () => ext)
|
||||
.replace(/\[name\]/gi, () => basename)
|
||||
.replace(/\[path\]/gi, () => directory)
|
||||
.replace(/\[folder\]/gi, () => folder)
|
||||
.replace(/\[query\]/gi, () => query);
|
||||
|
||||
if (regExp && loaderContext.resourcePath) {
|
||||
const match = loaderContext.resourcePath.match(new RegExp(regExp));
|
||||
|
||||
match &&
|
||||
match.forEach((matched, i) => {
|
||||
url = url.replace(new RegExp('\\[' + i + '\\]', 'ig'), matched);
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
typeof loaderContext.options === 'object' &&
|
||||
typeof loaderContext.options.customInterpolateName === 'function'
|
||||
) {
|
||||
url = loaderContext.options.customInterpolateName.call(
|
||||
loaderContext,
|
||||
url,
|
||||
name,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
module.exports = interpolateName;
|
||||
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
function isUrlRequest(url, root) {
|
||||
// An URL is not an request if
|
||||
|
||||
// 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
|
||||
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. It's a protocol-relative
|
||||
if (/^\/\//.test(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. It's some kind of url for a template
|
||||
if (/^[{}[\]#*;,'§$%&(=?`´^°<>]/.test(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. It's also not an request if root isn't set and it's a root-relative url
|
||||
if ((root === undefined || root === false) && /^\//.test(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = isUrlRequest;
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
const JSON5 = require('json5');
|
||||
|
||||
const specialValues = {
|
||||
null: null,
|
||||
true: true,
|
||||
false: false,
|
||||
};
|
||||
|
||||
function parseQuery(query) {
|
||||
if (query.substr(0, 1) !== '?') {
|
||||
throw new Error(
|
||||
"A valid query string passed to parseQuery should begin with '?'"
|
||||
);
|
||||
}
|
||||
|
||||
query = query.substr(1);
|
||||
|
||||
if (!query) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (query.substr(0, 1) === '{' && query.substr(-1) === '}') {
|
||||
return JSON5.parse(query);
|
||||
}
|
||||
|
||||
const queryArgs = query.split(/[,&]/g);
|
||||
const result = {};
|
||||
|
||||
queryArgs.forEach((arg) => {
|
||||
const idx = arg.indexOf('=');
|
||||
|
||||
if (idx >= 0) {
|
||||
let name = arg.substr(0, idx);
|
||||
let value = decodeURIComponent(arg.substr(idx + 1));
|
||||
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (specialValues.hasOwnProperty(value)) {
|
||||
value = specialValues[value];
|
||||
}
|
||||
|
||||
if (name.substr(-2) === '[]') {
|
||||
name = decodeURIComponent(name.substr(0, name.length - 2));
|
||||
|
||||
if (!Array.isArray(result[name])) {
|
||||
result[name] = [];
|
||||
}
|
||||
|
||||
result[name].push(value);
|
||||
} else {
|
||||
name = decodeURIComponent(name);
|
||||
result[name] = value;
|
||||
}
|
||||
} else {
|
||||
if (arg.substr(0, 1) === '-') {
|
||||
result[decodeURIComponent(arg.substr(1))] = false;
|
||||
} else if (arg.substr(0, 1) === '+') {
|
||||
result[decodeURIComponent(arg.substr(1))] = true;
|
||||
} else {
|
||||
result[decodeURIComponent(arg)] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = parseQuery;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
function parseString(str) {
|
||||
try {
|
||||
if (str[0] === '"') {
|
||||
return JSON.parse(str);
|
||||
}
|
||||
|
||||
if (str[0] === "'" && str.substr(str.length - 1) === "'") {
|
||||
return parseString(
|
||||
str
|
||||
.replace(/\\.|"/g, (x) => (x === '"' ? '\\"' : x))
|
||||
.replace(/^'|'$/g, '"')
|
||||
);
|
||||
}
|
||||
|
||||
return JSON.parse('"' + str + '"');
|
||||
} catch (e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = parseString;
|
||||
Generated
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const matchRelativePath = /^\.\.?[/\\]/;
|
||||
|
||||
function isAbsolutePath(str) {
|
||||
return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
|
||||
}
|
||||
|
||||
function isRelativePath(str) {
|
||||
return matchRelativePath.test(str);
|
||||
}
|
||||
|
||||
function stringifyRequest(loaderContext, request) {
|
||||
const splitted = request.split('!');
|
||||
const context =
|
||||
loaderContext.context ||
|
||||
(loaderContext.options && loaderContext.options.context);
|
||||
|
||||
return JSON.stringify(
|
||||
splitted
|
||||
.map((part) => {
|
||||
// First, separate singlePath from query, because the query might contain paths again
|
||||
const splittedPart = part.match(/^(.*?)(\?.*)/);
|
||||
const query = splittedPart ? splittedPart[2] : '';
|
||||
let singlePath = splittedPart ? splittedPart[1] : part;
|
||||
|
||||
if (isAbsolutePath(singlePath) && context) {
|
||||
singlePath = path.relative(context, singlePath);
|
||||
|
||||
if (isAbsolutePath(singlePath)) {
|
||||
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
||||
// In this case, we leave the path platform-specific without replacing any separators.
|
||||
// @see https://github.com/webpack/loader-utils/pull/14
|
||||
return singlePath + query;
|
||||
}
|
||||
|
||||
if (isRelativePath(singlePath) === false) {
|
||||
// Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
||||
singlePath = './' + singlePath;
|
||||
}
|
||||
}
|
||||
|
||||
return singlePath.replace(/\\/g, '/') + query;
|
||||
})
|
||||
.join('!')
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = stringifyRequest;
|
||||
Generated
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
// we can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
|
||||
const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
|
||||
|
||||
function urlToRequest(url, root) {
|
||||
// Do not rewrite an empty url
|
||||
if (url === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
const moduleRequestRegex = /^[^?]*~/;
|
||||
let request;
|
||||
|
||||
if (matchNativeWin32Path.test(url)) {
|
||||
// absolute windows path, keep it
|
||||
request = url;
|
||||
} else if (root !== undefined && root !== false && /^\//.test(url)) {
|
||||
// if root is set and the url is root-relative
|
||||
switch (typeof root) {
|
||||
// 1. root is a string: root is prefixed to the url
|
||||
case 'string':
|
||||
// special case: `~` roots convert to module request
|
||||
if (moduleRequestRegex.test(root)) {
|
||||
request = root.replace(/([^~/])$/, '$1/') + url.slice(1);
|
||||
} else {
|
||||
request = root + url;
|
||||
}
|
||||
break;
|
||||
// 2. root is `true`: absolute paths are allowed
|
||||
// *nix only, windows-style absolute paths are always allowed as they doesn't start with a `/`
|
||||
case 'boolean':
|
||||
request = url;
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
"Unexpected parameters to loader-utils 'urlToRequest': url = " +
|
||||
url +
|
||||
', root = ' +
|
||||
root +
|
||||
'.'
|
||||
);
|
||||
}
|
||||
} else if (/^\.\.?\//.test(url)) {
|
||||
// A relative url stays
|
||||
request = url;
|
||||
} else {
|
||||
// every other url is threaded like a relative url
|
||||
request = './' + url;
|
||||
}
|
||||
|
||||
// A `~` makes the url an module
|
||||
if (moduleRequestRegex.test(request)) {
|
||||
request = request.replace(moduleRequestRegex, '');
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
module.exports = urlToRequest;
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"loader-utils@2.0.2",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "loader-utils@2.0.2",
|
||||
"_id": "loader-utils@2.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
|
||||
"_location": "/style-resources-loader/loader-utils",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "loader-utils@2.0.2",
|
||||
"name": "loader-utils",
|
||||
"escapedName": "loader-utils",
|
||||
"rawSpec": "2.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/style-resources-loader"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz",
|
||||
"_spec": "2.0.2",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Tobias Koppers @sokra"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/webpack/loader-utils/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"big.js": "^5.2.2",
|
||||
"emojis-list": "^3.0.0",
|
||||
"json5": "^2.1.2"
|
||||
},
|
||||
"description": "utils for webpack loaders",
|
||||
"devDependencies": {
|
||||
"coveralls": "^3.0.9",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-node": "^11.0.0",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"jest": "^25.1.0",
|
||||
"prettier": "^1.19.1",
|
||||
"standard-version": "^7.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.9.0"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/webpack/loader-utils#readme",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "loader-utils",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/webpack/loader-utils.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint lib test",
|
||||
"pretest": "yarn lint",
|
||||
"release": "yarn test && standard-version",
|
||||
"test": "jest",
|
||||
"test:ci": "jest --coverage"
|
||||
},
|
||||
"version": "2.0.2"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/******************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
# tslib
|
||||
|
||||
This is a runtime library for [TypeScript](http://www.typescriptlang.org/) that contains all of the TypeScript helper functions.
|
||||
|
||||
This library is primarily used by the `--importHelpers` flag in TypeScript.
|
||||
When using `--importHelpers`, a module that uses helper functions like `__extends` and `__assign` in the following emitted file:
|
||||
|
||||
```ts
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
exports.x = {};
|
||||
exports.y = __assign({}, exports.x);
|
||||
|
||||
```
|
||||
|
||||
will instead be emitted as something like the following:
|
||||
|
||||
```ts
|
||||
var tslib_1 = require("tslib");
|
||||
exports.x = {};
|
||||
exports.y = tslib_1.__assign({}, exports.x);
|
||||
```
|
||||
|
||||
Because this can avoid duplicate declarations of things like `__extends`, `__assign`, etc., this means delivering users smaller files on average, as well as less runtime overhead.
|
||||
For optimized bundles with TypeScript, you should absolutely consider using `tslib` and `--importHelpers`.
|
||||
|
||||
# Installing
|
||||
|
||||
For the latest stable version, run:
|
||||
|
||||
## npm
|
||||
|
||||
```sh
|
||||
# TypeScript 3.9.2 or later
|
||||
npm install tslib
|
||||
|
||||
# TypeScript 3.8.4 or earlier
|
||||
npm install tslib@^1
|
||||
|
||||
# TypeScript 2.3.2 or earlier
|
||||
npm install tslib@1.6.1
|
||||
```
|
||||
|
||||
## yarn
|
||||
|
||||
```sh
|
||||
# TypeScript 3.9.2 or later
|
||||
yarn add tslib
|
||||
|
||||
# TypeScript 3.8.4 or earlier
|
||||
yarn add tslib@^1
|
||||
|
||||
# TypeScript 2.3.2 or earlier
|
||||
yarn add tslib@1.6.1
|
||||
```
|
||||
|
||||
## bower
|
||||
|
||||
```sh
|
||||
# TypeScript 3.9.2 or later
|
||||
bower install tslib
|
||||
|
||||
# TypeScript 3.8.4 or earlier
|
||||
bower install tslib@^1
|
||||
|
||||
# TypeScript 2.3.2 or earlier
|
||||
bower install tslib@1.6.1
|
||||
```
|
||||
|
||||
## JSPM
|
||||
|
||||
```sh
|
||||
# TypeScript 3.9.2 or later
|
||||
jspm install tslib
|
||||
|
||||
# TypeScript 3.8.4 or earlier
|
||||
jspm install tslib@^1
|
||||
|
||||
# TypeScript 2.3.2 or earlier
|
||||
jspm install tslib@1.6.1
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
Set the `importHelpers` compiler option on the command line:
|
||||
|
||||
```
|
||||
tsc --importHelpers file.ts
|
||||
```
|
||||
|
||||
or in your tsconfig.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"importHelpers": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### For bower and JSPM users
|
||||
|
||||
You will need to add a `paths` mapping for `tslib`, e.g. For Bower users:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "amd",
|
||||
"importHelpers": true,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"tslib" : ["bower_components/tslib/tslib.d.ts"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For JSPM users:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "system",
|
||||
"importHelpers": true,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"tslib" : ["jspm_packages/npm/tslib@2.x.y/tslib.d.ts"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
- Choose your new version number
|
||||
- Set it in `package.json` and `bower.json`
|
||||
- Create a tag: `git tag [version]`
|
||||
- Push the tag: `git push --tags`
|
||||
- Create a [release in GitHub](https://github.com/microsoft/tslib/releases)
|
||||
- Run the [publish to npm](https://github.com/microsoft/tslib/actions?query=workflow%3A%22Publish+to+NPM%22) workflow
|
||||
|
||||
Done.
|
||||
|
||||
# Contribute
|
||||
|
||||
There are many ways to [contribute](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md) to TypeScript.
|
||||
|
||||
* [Submit bugs](https://github.com/Microsoft/TypeScript/issues) and help us verify fixes as they are checked in.
|
||||
* Review the [source code changes](https://github.com/Microsoft/TypeScript/pulls).
|
||||
* Engage with other TypeScript users and developers on [StackOverflow](http://stackoverflow.com/questions/tagged/typescript).
|
||||
* Join the [#typescript](http://twitter.com/#!/search/realtime/%23typescript) discussion on Twitter.
|
||||
* [Contribute bug fixes](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md).
|
||||
|
||||
# Documentation
|
||||
|
||||
* [Quick tutorial](http://www.typescriptlang.org/Tutorial)
|
||||
* [Programming handbook](http://www.typescriptlang.org/Handbook)
|
||||
* [Homepage](http://www.typescriptlang.org/)
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import tslib from '../tslib.js';
|
||||
const {
|
||||
__extends,
|
||||
__assign,
|
||||
__rest,
|
||||
__decorate,
|
||||
__param,
|
||||
__metadata,
|
||||
__awaiter,
|
||||
__generator,
|
||||
__exportStar,
|
||||
__createBinding,
|
||||
__values,
|
||||
__read,
|
||||
__spread,
|
||||
__spreadArrays,
|
||||
__spreadArray,
|
||||
__await,
|
||||
__asyncGenerator,
|
||||
__asyncDelegator,
|
||||
__asyncValues,
|
||||
__makeTemplateObject,
|
||||
__importStar,
|
||||
__importDefault,
|
||||
__classPrivateFieldGet,
|
||||
__classPrivateFieldSet,
|
||||
__classPrivateFieldIn,
|
||||
} = tslib;
|
||||
export {
|
||||
__extends,
|
||||
__assign,
|
||||
__rest,
|
||||
__decorate,
|
||||
__param,
|
||||
__metadata,
|
||||
__awaiter,
|
||||
__generator,
|
||||
__exportStar,
|
||||
__createBinding,
|
||||
__values,
|
||||
__read,
|
||||
__spread,
|
||||
__spreadArrays,
|
||||
__spreadArray,
|
||||
__await,
|
||||
__asyncGenerator,
|
||||
__asyncDelegator,
|
||||
__asyncValues,
|
||||
__makeTemplateObject,
|
||||
__importStar,
|
||||
__importDefault,
|
||||
__classPrivateFieldGet,
|
||||
__classPrivateFieldSet,
|
||||
__classPrivateFieldIn,
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"tslib@2.4.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "tslib@2.4.0",
|
||||
"_id": "tslib@2.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==",
|
||||
"_location": "/style-resources-loader/tslib",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "tslib@2.4.0",
|
||||
"name": "tslib",
|
||||
"escapedName": "tslib",
|
||||
"rawSpec": "2.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/style-resources-loader"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
|
||||
"_spec": "2.4.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Microsoft Corp."
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Microsoft/TypeScript/issues"
|
||||
},
|
||||
"description": "Runtime library for TypeScript helper functions",
|
||||
"exports": {
|
||||
".": {
|
||||
"module": "./tslib.es6.js",
|
||||
"import": "./modules/index.js",
|
||||
"default": "./tslib.js"
|
||||
},
|
||||
"./*": "./*",
|
||||
"./": "./"
|
||||
},
|
||||
"homepage": "https://www.typescriptlang.org/",
|
||||
"jsnext:main": "tslib.es6.js",
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"Microsoft",
|
||||
"compiler",
|
||||
"language",
|
||||
"javascript",
|
||||
"tslib",
|
||||
"runtime"
|
||||
],
|
||||
"license": "0BSD",
|
||||
"main": "tslib.js",
|
||||
"module": "tslib.es6.js",
|
||||
"name": "tslib",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Microsoft/tslib.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"typings": "tslib.d.ts",
|
||||
"version": "2.4.0"
|
||||
}
|
||||
+398
@@ -0,0 +1,398 @@
|
||||
/******************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/**
|
||||
* Used to shim class extends.
|
||||
*
|
||||
* @param d The derived class.
|
||||
* @param b The base class.
|
||||
*/
|
||||
export declare function __extends(d: Function, b: Function): void;
|
||||
|
||||
/**
|
||||
* Copy the values of all of the enumerable own properties from one or more source objects to a
|
||||
* target object. Returns the target object.
|
||||
*
|
||||
* @param t The target object to copy to.
|
||||
* @param sources One or more source objects from which to copy properties
|
||||
*/
|
||||
export declare function __assign(t: any, ...sources: any[]): any;
|
||||
|
||||
/**
|
||||
* Performs a rest spread on an object.
|
||||
*
|
||||
* @param t The source value.
|
||||
* @param propertyNames The property names excluded from the rest spread.
|
||||
*/
|
||||
export declare function __rest(t: any, propertyNames: (string | symbol)[]): any;
|
||||
|
||||
/**
|
||||
* Applies decorators to a target object
|
||||
*
|
||||
* @param decorators The set of decorators to apply.
|
||||
* @param target The target object.
|
||||
* @param key If specified, the own property to apply the decorators to.
|
||||
* @param desc The property descriptor, defaults to fetching the descriptor from the target object.
|
||||
* @experimental
|
||||
*/
|
||||
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
|
||||
|
||||
/**
|
||||
* Creates an observing function decorator from a parameter decorator.
|
||||
*
|
||||
* @param paramIndex The parameter index to apply the decorator to.
|
||||
* @param decorator The parameter decorator to apply. Note that the return value is ignored.
|
||||
* @experimental
|
||||
*/
|
||||
export declare function __param(paramIndex: number, decorator: Function): Function;
|
||||
|
||||
/**
|
||||
* Creates a decorator that sets metadata.
|
||||
*
|
||||
* @param metadataKey The metadata key
|
||||
* @param metadataValue The metadata value
|
||||
* @experimental
|
||||
*/
|
||||
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
|
||||
|
||||
/**
|
||||
* Converts a generator function into a pseudo-async function, by treating each `yield` as an `await`.
|
||||
*
|
||||
* @param thisArg The reference to use as the `this` value in the generator function
|
||||
* @param _arguments The optional arguments array
|
||||
* @param P The optional promise constructor argument, defaults to the `Promise` property of the global object.
|
||||
* @param generator The generator function
|
||||
*/
|
||||
export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;
|
||||
|
||||
/**
|
||||
* Creates an Iterator object using the body as the implementation.
|
||||
*
|
||||
* @param thisArg The reference to use as the `this` value in the function
|
||||
* @param body The generator state-machine based implementation.
|
||||
*
|
||||
* @see [./docs/generator.md]
|
||||
*/
|
||||
export declare function __generator(thisArg: any, body: Function): any;
|
||||
|
||||
/**
|
||||
* Creates bindings for all enumerable properties of `m` on `exports`
|
||||
*
|
||||
* @param m The source object
|
||||
* @param exports The `exports` object.
|
||||
*/
|
||||
export declare function __exportStar(m: any, o: any): void;
|
||||
|
||||
/**
|
||||
* Creates a value iterator from an `Iterable` or `ArrayLike` object.
|
||||
*
|
||||
* @param o The object.
|
||||
* @throws {TypeError} If `o` is neither `Iterable`, nor an `ArrayLike`.
|
||||
*/
|
||||
export declare function __values(o: any): any;
|
||||
|
||||
/**
|
||||
* Reads values from an `Iterable` or `ArrayLike` object and returns the resulting array.
|
||||
*
|
||||
* @param o The object to read from.
|
||||
* @param n The maximum number of arguments to read, defaults to `Infinity`.
|
||||
*/
|
||||
export declare function __read(o: any, n?: number): any[];
|
||||
|
||||
/**
|
||||
* Creates an array from iterable spread.
|
||||
*
|
||||
* @param args The Iterable objects to spread.
|
||||
* @deprecated since TypeScript 4.2 - Use `__spreadArray`
|
||||
*/
|
||||
export declare function __spread(...args: any[][]): any[];
|
||||
|
||||
/**
|
||||
* Creates an array from array spread.
|
||||
*
|
||||
* @param args The ArrayLikes to spread into the resulting array.
|
||||
* @deprecated since TypeScript 4.2 - Use `__spreadArray`
|
||||
*/
|
||||
export declare function __spreadArrays(...args: any[][]): any[];
|
||||
|
||||
/**
|
||||
* Spreads the `from` array into the `to` array.
|
||||
*
|
||||
* @param pack Replace empty elements with `undefined`.
|
||||
*/
|
||||
export declare function __spreadArray(to: any[], from: any[], pack?: boolean): any[];
|
||||
|
||||
/**
|
||||
* Creates an object that signals to `__asyncGenerator` that it shouldn't be yielded,
|
||||
* and instead should be awaited and the resulting value passed back to the generator.
|
||||
*
|
||||
* @param v The value to await.
|
||||
*/
|
||||
export declare function __await(v: any): any;
|
||||
|
||||
/**
|
||||
* Converts a generator function into an async generator function, by using `yield __await`
|
||||
* in place of normal `await`.
|
||||
*
|
||||
* @param thisArg The reference to use as the `this` value in the generator function
|
||||
* @param _arguments The optional arguments array
|
||||
* @param generator The generator function
|
||||
*/
|
||||
export declare function __asyncGenerator(thisArg: any, _arguments: any, generator: Function): any;
|
||||
|
||||
/**
|
||||
* Used to wrap a potentially async iterator in such a way so that it wraps the result
|
||||
* of calling iterator methods of `o` in `__await` instances, and then yields the awaited values.
|
||||
*
|
||||
* @param o The potentially async iterator.
|
||||
* @returns A synchronous iterator yielding `__await` instances on every odd invocation
|
||||
* and returning the awaited `IteratorResult` passed to `next` every even invocation.
|
||||
*/
|
||||
export declare function __asyncDelegator(o: any): any;
|
||||
|
||||
/**
|
||||
* Creates a value async iterator from an `AsyncIterable`, `Iterable` or `ArrayLike` object.
|
||||
*
|
||||
* @param o The object.
|
||||
* @throws {TypeError} If `o` is neither `AsyncIterable`, `Iterable`, nor an `ArrayLike`.
|
||||
*/
|
||||
export declare function __asyncValues(o: any): any;
|
||||
|
||||
/**
|
||||
* Creates a `TemplateStringsArray` frozen object from the `cooked` and `raw` arrays.
|
||||
*
|
||||
* @param cooked The cooked possibly-sparse array.
|
||||
* @param raw The raw string content.
|
||||
*/
|
||||
export declare function __makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray;
|
||||
|
||||
/**
|
||||
* Used to shim default and named imports in ECMAScript Modules transpiled to CommonJS.
|
||||
*
|
||||
* ```js
|
||||
* import Default, { Named, Other } from "mod";
|
||||
* // or
|
||||
* import { default as Default, Named, Other } from "mod";
|
||||
* ```
|
||||
*
|
||||
* @param mod The CommonJS module exports object.
|
||||
*/
|
||||
export declare function __importStar<T>(mod: T): T;
|
||||
|
||||
/**
|
||||
* Used to shim default imports in ECMAScript Modules transpiled to CommonJS.
|
||||
*
|
||||
* ```js
|
||||
* import Default from "mod";
|
||||
* ```
|
||||
*
|
||||
* @param mod The CommonJS module exports object.
|
||||
*/
|
||||
export declare function __importDefault<T>(mod: T): T | { default: T };
|
||||
|
||||
/**
|
||||
* Emulates reading a private instance field.
|
||||
*
|
||||
* @param receiver The instance from which to read the private field.
|
||||
* @param state A WeakMap containing the private field value for an instance.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
*
|
||||
* @throws {TypeError} If `state` doesn't have an entry for `receiver`.
|
||||
*/
|
||||
export declare function __classPrivateFieldGet<T extends object, V>(
|
||||
receiver: T,
|
||||
state: { has(o: T): boolean, get(o: T): V | undefined },
|
||||
kind?: "f"
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates reading a private static field.
|
||||
*
|
||||
* @param receiver The object from which to read the private static field.
|
||||
* @param state The class constructor containing the definition of the static field.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The descriptor that holds the static field value.
|
||||
*
|
||||
* @throws {TypeError} If `receiver` is not `state`.
|
||||
*/
|
||||
export declare function __classPrivateFieldGet<T extends new (...args: any[]) => unknown, V>(
|
||||
receiver: T,
|
||||
state: T,
|
||||
kind: "f",
|
||||
f: { value: V }
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates evaluating a private instance "get" accessor.
|
||||
*
|
||||
* @param receiver The instance on which to evaluate the private "get" accessor.
|
||||
* @param state A WeakSet used to verify an instance supports the private "get" accessor.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The "get" accessor function to evaluate.
|
||||
*
|
||||
* @throws {TypeError} If `state` doesn't have an entry for `receiver`.
|
||||
*/
|
||||
export declare function __classPrivateFieldGet<T extends object, V>(
|
||||
receiver: T,
|
||||
state: { has(o: T): boolean },
|
||||
kind: "a",
|
||||
f: () => V
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates evaluating a private static "get" accessor.
|
||||
*
|
||||
* @param receiver The object on which to evaluate the private static "get" accessor.
|
||||
* @param state The class constructor containing the definition of the static "get" accessor.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The "get" accessor function to evaluate.
|
||||
*
|
||||
* @throws {TypeError} If `receiver` is not `state`.
|
||||
*/
|
||||
export declare function __classPrivateFieldGet<T extends new (...args: any[]) => unknown, V>(
|
||||
receiver: T,
|
||||
state: T,
|
||||
kind: "a",
|
||||
f: () => V
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates reading a private instance method.
|
||||
*
|
||||
* @param receiver The instance from which to read a private method.
|
||||
* @param state A WeakSet used to verify an instance supports the private method.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The function to return as the private instance method.
|
||||
*
|
||||
* @throws {TypeError} If `state` doesn't have an entry for `receiver`.
|
||||
*/
|
||||
export declare function __classPrivateFieldGet<T extends object, V extends (...args: any[]) => unknown>(
|
||||
receiver: T,
|
||||
state: { has(o: T): boolean },
|
||||
kind: "m",
|
||||
f: V
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates reading a private static method.
|
||||
*
|
||||
* @param receiver The object from which to read the private static method.
|
||||
* @param state The class constructor containing the definition of the static method.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The function to return as the private static method.
|
||||
*
|
||||
* @throws {TypeError} If `receiver` is not `state`.
|
||||
*/
|
||||
export declare function __classPrivateFieldGet<T extends new (...args: any[]) => unknown, V extends (...args: any[]) => unknown>(
|
||||
receiver: T,
|
||||
state: T,
|
||||
kind: "m",
|
||||
f: V
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates writing to a private instance field.
|
||||
*
|
||||
* @param receiver The instance on which to set a private field value.
|
||||
* @param state A WeakMap used to store the private field value for an instance.
|
||||
* @param value The value to store in the private field.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
*
|
||||
* @throws {TypeError} If `state` doesn't have an entry for `receiver`.
|
||||
*/
|
||||
export declare function __classPrivateFieldSet<T extends object, V>(
|
||||
receiver: T,
|
||||
state: { has(o: T): boolean, set(o: T, value: V): unknown },
|
||||
value: V,
|
||||
kind?: "f"
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates writing to a private static field.
|
||||
*
|
||||
* @param receiver The object on which to set the private static field.
|
||||
* @param state The class constructor containing the definition of the private static field.
|
||||
* @param value The value to store in the private field.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The descriptor that holds the static field value.
|
||||
*
|
||||
* @throws {TypeError} If `receiver` is not `state`.
|
||||
*/
|
||||
export declare function __classPrivateFieldSet<T extends new (...args: any[]) => unknown, V>(
|
||||
receiver: T,
|
||||
state: T,
|
||||
value: V,
|
||||
kind: "f",
|
||||
f: { value: V }
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates writing to a private instance "set" accessor.
|
||||
*
|
||||
* @param receiver The instance on which to evaluate the private instance "set" accessor.
|
||||
* @param state A WeakSet used to verify an instance supports the private "set" accessor.
|
||||
* @param value The value to store in the private accessor.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The "set" accessor function to evaluate.
|
||||
*
|
||||
* @throws {TypeError} If `state` doesn't have an entry for `receiver`.
|
||||
*/
|
||||
export declare function __classPrivateFieldSet<T extends object, V>(
|
||||
receiver: T,
|
||||
state: { has(o: T): boolean },
|
||||
value: V,
|
||||
kind: "a",
|
||||
f: (v: V) => void
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Emulates writing to a private static "set" accessor.
|
||||
*
|
||||
* @param receiver The object on which to evaluate the private static "set" accessor.
|
||||
* @param state The class constructor containing the definition of the static "set" accessor.
|
||||
* @param value The value to store in the private field.
|
||||
* @param kind Either `"f"` for a field, `"a"` for an accessor, or `"m"` for a method.
|
||||
* @param f The "set" accessor function to evaluate.
|
||||
*
|
||||
* @throws {TypeError} If `receiver` is not `state`.
|
||||
*/
|
||||
export declare function __classPrivateFieldSet<T extends new (...args: any[]) => unknown, V>(
|
||||
receiver: T,
|
||||
state: T,
|
||||
value: V,
|
||||
kind: "a",
|
||||
f: (v: V) => void
|
||||
): V;
|
||||
|
||||
/**
|
||||
* Checks for the existence of a private field/method/accessor.
|
||||
*
|
||||
* @param state The class constructor containing the static member, or the WeakMap or WeakSet associated with a private instance member.
|
||||
* @param receiver The object for which to test the presence of the private member.
|
||||
*/
|
||||
export declare function __classPrivateFieldIn(
|
||||
state: (new (...args: any[]) => unknown) | { has(o: any): boolean },
|
||||
receiver: unknown,
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* Creates a re-export binding on `object` with key `objectKey` that references `target[key]`.
|
||||
*
|
||||
* @param object The local `exports` object.
|
||||
* @param target The object to re-export from.
|
||||
* @param key The property key of `target` to re-export.
|
||||
* @param objectKey The property key to re-export as. Defaults to `key`.
|
||||
*/
|
||||
export declare function __createBinding(object: object, target: object, key: PropertyKey, objectKey?: PropertyKey): void;
|
||||
+1
@@ -0,0 +1 @@
|
||||
<script src="tslib.es6.js"></script>
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
/******************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
/* global Reflect, Promise */
|
||||
|
||||
var extendStatics = function(d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
|
||||
export function __extends(d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
}
|
||||
|
||||
export var __assign = function() {
|
||||
__assign = Object.assign || function __assign(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
return __assign.apply(this, arguments);
|
||||
}
|
||||
|
||||
export function __rest(s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
export function __decorate(decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
}
|
||||
|
||||
export function __param(paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
}
|
||||
|
||||
export function __metadata(metadataKey, metadataValue) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
||||
}
|
||||
|
||||
export function __awaiter(thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
}
|
||||
|
||||
export function __generator(thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
}
|
||||
|
||||
export var __createBinding = Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
});
|
||||
|
||||
export function __exportStar(m, o) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
|
||||
}
|
||||
|
||||
export function __values(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
}
|
||||
|
||||
export function __read(o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export function __spread() {
|
||||
for (var ar = [], i = 0; i < arguments.length; i++)
|
||||
ar = ar.concat(__read(arguments[i]));
|
||||
return ar;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export function __spreadArrays() {
|
||||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
||||
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
||||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
||||
r[k] = a[j];
|
||||
return r;
|
||||
}
|
||||
|
||||
export function __spreadArray(to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
}
|
||||
|
||||
export function __await(v) {
|
||||
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
||||
}
|
||||
|
||||
export function __asyncGenerator(thisArg, _arguments, generator) {
|
||||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
||||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
||||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
||||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
||||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
||||
function fulfill(value) { resume("next", value); }
|
||||
function reject(value) { resume("throw", value); }
|
||||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
||||
}
|
||||
|
||||
export function __asyncDelegator(o) {
|
||||
var i, p;
|
||||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
||||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
||||
}
|
||||
|
||||
export function __asyncValues(o) {
|
||||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||
var m = o[Symbol.asyncIterator], i;
|
||||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
||||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
||||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
||||
}
|
||||
|
||||
export function __makeTemplateObject(cooked, raw) {
|
||||
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
||||
return cooked;
|
||||
};
|
||||
|
||||
var __setModuleDefault = Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
};
|
||||
|
||||
export function __importStar(mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function __importDefault(mod) {
|
||||
return (mod && mod.__esModule) ? mod : { default: mod };
|
||||
}
|
||||
|
||||
export function __classPrivateFieldGet(receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
}
|
||||
|
||||
export function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
}
|
||||
|
||||
export function __classPrivateFieldIn(state, receiver) {
|
||||
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
|
||||
return typeof state === "function" ? receiver === state : state.has(receiver);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<script src="tslib.js"></script>
|
||||
+317
@@ -0,0 +1,317 @@
|
||||
/******************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
/* global global, define, System, Reflect, Promise */
|
||||
var __extends;
|
||||
var __assign;
|
||||
var __rest;
|
||||
var __decorate;
|
||||
var __param;
|
||||
var __metadata;
|
||||
var __awaiter;
|
||||
var __generator;
|
||||
var __exportStar;
|
||||
var __values;
|
||||
var __read;
|
||||
var __spread;
|
||||
var __spreadArrays;
|
||||
var __spreadArray;
|
||||
var __await;
|
||||
var __asyncGenerator;
|
||||
var __asyncDelegator;
|
||||
var __asyncValues;
|
||||
var __makeTemplateObject;
|
||||
var __importStar;
|
||||
var __importDefault;
|
||||
var __classPrivateFieldGet;
|
||||
var __classPrivateFieldSet;
|
||||
var __classPrivateFieldIn;
|
||||
var __createBinding;
|
||||
(function (factory) {
|
||||
var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {};
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define("tslib", ["exports"], function (exports) { factory(createExporter(root, createExporter(exports))); });
|
||||
}
|
||||
else if (typeof module === "object" && typeof module.exports === "object") {
|
||||
factory(createExporter(root, createExporter(module.exports)));
|
||||
}
|
||||
else {
|
||||
factory(createExporter(root));
|
||||
}
|
||||
function createExporter(exports, previous) {
|
||||
if (exports !== root) {
|
||||
if (typeof Object.create === "function") {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
}
|
||||
else {
|
||||
exports.__esModule = true;
|
||||
}
|
||||
}
|
||||
return function (id, v) { return exports[id] = previous ? previous(id, v) : v; };
|
||||
}
|
||||
})
|
||||
(function (exporter) {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
|
||||
__extends = function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
|
||||
__assign = Object.assign || function (t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
|
||||
__rest = function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
|
||||
__decorate = function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
|
||||
__param = function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
|
||||
__metadata = function (metadataKey, metadataValue) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
||||
};
|
||||
|
||||
__awaiter = function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
||||
__generator = function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
|
||||
__exportStar = function(m, o) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
|
||||
};
|
||||
|
||||
__createBinding = Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
});
|
||||
|
||||
__values = function (o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};
|
||||
|
||||
__read = function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
__spread = function () {
|
||||
for (var ar = [], i = 0; i < arguments.length; i++)
|
||||
ar = ar.concat(__read(arguments[i]));
|
||||
return ar;
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
__spreadArrays = function () {
|
||||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
||||
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
||||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
||||
r[k] = a[j];
|
||||
return r;
|
||||
};
|
||||
|
||||
__spreadArray = function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
|
||||
__await = function (v) {
|
||||
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
||||
};
|
||||
|
||||
__asyncGenerator = function (thisArg, _arguments, generator) {
|
||||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
||||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
||||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
||||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
||||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
||||
function fulfill(value) { resume("next", value); }
|
||||
function reject(value) { resume("throw", value); }
|
||||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
||||
};
|
||||
|
||||
__asyncDelegator = function (o) {
|
||||
var i, p;
|
||||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
||||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
||||
};
|
||||
|
||||
__asyncValues = function (o) {
|
||||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||
var m = o[Symbol.asyncIterator], i;
|
||||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
||||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
||||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
||||
};
|
||||
|
||||
__makeTemplateObject = function (cooked, raw) {
|
||||
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
||||
return cooked;
|
||||
};
|
||||
|
||||
var __setModuleDefault = Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
};
|
||||
|
||||
__importStar = function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
|
||||
__importDefault = function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
|
||||
__classPrivateFieldGet = function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
|
||||
__classPrivateFieldSet = function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
|
||||
__classPrivateFieldIn = function (state, receiver) {
|
||||
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
|
||||
return typeof state === "function" ? receiver === state : state.has(receiver);
|
||||
};
|
||||
|
||||
exporter("__extends", __extends);
|
||||
exporter("__assign", __assign);
|
||||
exporter("__rest", __rest);
|
||||
exporter("__decorate", __decorate);
|
||||
exporter("__param", __param);
|
||||
exporter("__metadata", __metadata);
|
||||
exporter("__awaiter", __awaiter);
|
||||
exporter("__generator", __generator);
|
||||
exporter("__exportStar", __exportStar);
|
||||
exporter("__createBinding", __createBinding);
|
||||
exporter("__values", __values);
|
||||
exporter("__read", __read);
|
||||
exporter("__spread", __spread);
|
||||
exporter("__spreadArrays", __spreadArrays);
|
||||
exporter("__spreadArray", __spreadArray);
|
||||
exporter("__await", __await);
|
||||
exporter("__asyncGenerator", __asyncGenerator);
|
||||
exporter("__asyncDelegator", __asyncDelegator);
|
||||
exporter("__asyncValues", __asyncValues);
|
||||
exporter("__makeTemplateObject", __makeTemplateObject);
|
||||
exporter("__importStar", __importStar);
|
||||
exporter("__importDefault", __importDefault);
|
||||
exporter("__classPrivateFieldGet", __classPrivateFieldGet);
|
||||
exporter("__classPrivateFieldSet", __classPrivateFieldSet);
|
||||
exporter("__classPrivateFieldIn", __classPrivateFieldIn);
|
||||
});
|
||||
+52
-48
@@ -1,34 +1,38 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"style-resources-loader@1.3.3",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"style-resources-loader@1.5.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "style-resources-loader@1.3.3",
|
||||
"_id": "style-resources-loader@1.3.3",
|
||||
"_from": "style-resources-loader@1.5.0",
|
||||
"_id": "style-resources-loader@1.5.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-vDD2HyG6On8H9gWUN9O9q1eXR/JnXpCkNvpusvgFsRQ9JZGF9drzvwKEigR9vqlmUbXO2t/vIIabpYMmis0eAQ==",
|
||||
"_integrity": "sha512-fIfyvQ+uvXaCBGGAgfh+9v46ARQB1AWdaop2RpQw0PBVuROsTBqGvx8dj0kxwjGOAyq3vepe4AOK3M6+Q/q2jw==",
|
||||
"_location": "/style-resources-loader",
|
||||
"_phantomChildren": {},
|
||||
"_phantomChildren": {
|
||||
"big.js": "5.2.2",
|
||||
"emojis-list": "3.0.0",
|
||||
"json5": "2.2.1"
|
||||
},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "style-resources-loader@1.3.3",
|
||||
"raw": "style-resources-loader@1.5.0",
|
||||
"name": "style-resources-loader",
|
||||
"escapedName": "style-resources-loader",
|
||||
"rawSpec": "1.3.3",
|
||||
"rawSpec": "1.5.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.3.3"
|
||||
"fetchSpec": "1.5.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@nuxt/webpack"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/style-resources-loader/-/style-resources-loader-1.3.3.tgz",
|
||||
"_spec": "1.3.3",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/style-resources-loader/-/style-resources-loader-1.5.0.tgz",
|
||||
"_spec": "1.5.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Shi Yan",
|
||||
"name": "Yan Shi",
|
||||
"email": "yenshih95@gmail.com",
|
||||
"url": "https://github.com/yenshih"
|
||||
},
|
||||
@@ -36,42 +40,42 @@
|
||||
"url": "https://github.com/yenshih/style-resources-loader/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"glob": "^7.1.6",
|
||||
"is-promise": "^2.1.0",
|
||||
"loader-utils": "^1.2.3",
|
||||
"schema-utils": "^2.6.1"
|
||||
"glob": "^7.2.0",
|
||||
"loader-utils": "^2.0.0",
|
||||
"schema-utils": "^2.7.0",
|
||||
"tslib": "^2.3.1"
|
||||
},
|
||||
"description": "CSS processor resources loader for webpack",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^8.2.0",
|
||||
"@commitlint/config-conventional": "^8.2.0",
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/is-promise": "^2.1.0",
|
||||
"@types/jest": "^24.0.24",
|
||||
"@types/loader-utils": "^1.1.3",
|
||||
"@types/node": "^12.12.21",
|
||||
"@types/webpack": "^4.41.0",
|
||||
"@types/webpack-merge": "^4.1.5",
|
||||
"@typescript-eslint/eslint-plugin": "^2.12.0",
|
||||
"@typescript-eslint/parser": "^2.12.0",
|
||||
"coveralls": "^3.0.9",
|
||||
"cross-env": "^6.0.3",
|
||||
"eslint": "^6.7.2",
|
||||
"eslint-config-prettier": "^6.7.0",
|
||||
"eslint-plugin-import": "^2.19.1",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"husky": "^3.1.0",
|
||||
"jest": "^24.9.0",
|
||||
"lint-staged": "^9.5.0",
|
||||
"prettier": "^1.19.1",
|
||||
"raw-loader": "^4.0.0",
|
||||
"ts-jest": "^24.2.0",
|
||||
"typescript": "^3.7.3",
|
||||
"webpack": "^4.41.3",
|
||||
"webpack-merge": "^4.2.2"
|
||||
"@commitlint/cli": "^15.0.0",
|
||||
"@commitlint/config-conventional": "^15.0.0",
|
||||
"@types/glob": "^7.2.0",
|
||||
"@types/is-promise": "^2.2.0",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/loader-utils": "^2.0.3",
|
||||
"@types/node": "^16.11.12",
|
||||
"@types/webpack": "^4.41.25",
|
||||
"@types/webpack-merge": "^5.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
||||
"@typescript-eslint/parser": "^5.6.0",
|
||||
"coveralls": "^3.1.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.4.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"husky": "^7.0.4",
|
||||
"jest": "^27.4.3",
|
||||
"lint-staged": "^12.1.2",
|
||||
"prettier": "^2.5.1",
|
||||
"raw-loader": "^4.0.2",
|
||||
"ts-jest": "^27.1.0",
|
||||
"typescript": "^4.5.2",
|
||||
"webpack": "^4.46.0",
|
||||
"webpack-merge": "^5.8.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=7.6"
|
||||
"node": ">=8.9"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
@@ -97,7 +101,7 @@
|
||||
"main": "lib/index.js",
|
||||
"name": "style-resources-loader",
|
||||
"peerDependencies": {
|
||||
"webpack": "^3.0.0 || ^4.0.0"
|
||||
"webpack": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -110,10 +114,10 @@
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
||||
"posttest": "rimraf test/**/outputs",
|
||||
"prepare": "npm run clean && npm run lint && npm run build && npm run coverage",
|
||||
"prettier": "prettier {src,test}/**/*.{js,jsx,ts,tsx} --write",
|
||||
"prettier": "prettier {src,test}/**/*.ts --write",
|
||||
"start": "tsc -w",
|
||||
"test": "jest --detectOpenHandles"
|
||||
"test": "jest"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "1.3.3"
|
||||
"version": "1.5.0"
|
||||
}
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
import loader from './loader';
|
||||
|
||||
export * from './schema';
|
||||
export * from './types';
|
||||
|
||||
export default loader;
|
||||
|
||||
+4
-7
@@ -1,10 +1,9 @@
|
||||
import {errorMessage, isFunction, loadResources} from './utils';
|
||||
|
||||
import {Loader, LoaderCallback} from '.';
|
||||
import type {Loader, LoaderCallback} from '.';
|
||||
|
||||
/* eslint-disable no-invalid-this */
|
||||
const loader: Loader = function(source) {
|
||||
this.cacheable && this.cacheable();
|
||||
const loader: Loader = function (source) {
|
||||
this.cacheable();
|
||||
|
||||
const callback = this.async();
|
||||
|
||||
@@ -17,9 +16,7 @@ const loader: Loader = function(source) {
|
||||
throw new Error(errorMessage.impossible);
|
||||
}
|
||||
|
||||
/* eslint-disable-next-line @typescript-eslint/no-floating-promises */
|
||||
loadResources(this, source, callback);
|
||||
void loadResources(this, source, callback);
|
||||
};
|
||||
/* eslint-enable no-invalid-this */
|
||||
|
||||
export default loader;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import validate from 'schema-utils';
|
||||
import type validate from 'schema-utils';
|
||||
|
||||
type Schema = Parameters<typeof validate>[0];
|
||||
|
||||
|
||||
+7
-3
@@ -1,5 +1,5 @@
|
||||
import {loader} from 'webpack';
|
||||
import glob from 'glob';
|
||||
import type {loader} from 'webpack';
|
||||
import type glob from 'glob';
|
||||
|
||||
export type Loader = loader.Loader;
|
||||
|
||||
@@ -16,7 +16,11 @@ export interface StyleResource {
|
||||
|
||||
export type StyleResources = StyleResource[];
|
||||
|
||||
export type StyleResourcesFunctionalInjector = (source: string, resources: StyleResources) => string | Promise<string>;
|
||||
export type StyleResourcesFunctionalInjector = (
|
||||
this: LoaderContext,
|
||||
source: string,
|
||||
resources: StyleResources,
|
||||
) => string | Promise<string>;
|
||||
|
||||
export type StyleResourcesInjector = 'prepend' | 'append' | StyleResourcesFunctionalInjector;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import {StyleResourcesFileFormat} from '..';
|
||||
import type {StyleResourcesFileFormat} from '../types';
|
||||
|
||||
export const PACKAGE_NAME = 'style-resources-loader';
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import {PACKAGE_NAME, ISSUES_URL} from '.';
|
||||
import {PACKAGE_NAME, ISSUES_URL} from './constants';
|
||||
|
||||
const formatErrorMessage = (message: string) => `[${PACKAGE_NAME}] ${message}`;
|
||||
|
||||
|
||||
+3
-2
@@ -1,9 +1,10 @@
|
||||
import fs from 'fs';
|
||||
import util from 'util';
|
||||
|
||||
import {LoaderContext, StyleResource, StyleResourcesLoaderNormalizedOptions} from '..';
|
||||
import type {LoaderContext, StyleResource, StyleResourcesLoaderNormalizedOptions} from '../types';
|
||||
|
||||
import {matchFiles, resolveImportUrl} from '.';
|
||||
import {matchFiles} from './match-files';
|
||||
import {resolveImportUrl} from './resolve-import-url';
|
||||
|
||||
export const getResources = async (ctx: LoaderContext, options: StyleResourcesLoaderNormalizedOptions) => {
|
||||
const {resolveUrl} = options;
|
||||
|
||||
+6
-4
@@ -1,17 +1,19 @@
|
||||
import {StyleResources, StyleResourcesLoaderNormalizedOptions} from '..';
|
||||
import type {LoaderContext} from '../types';
|
||||
import type {StyleResources, StyleResourcesLoaderNormalizedOptions} from '..';
|
||||
|
||||
import {isPromise, errorMessage} from '.';
|
||||
import {errorMessage} from './error-message';
|
||||
|
||||
export const injectResources = async (
|
||||
ctx: LoaderContext,
|
||||
options: StyleResourcesLoaderNormalizedOptions,
|
||||
source: string,
|
||||
resources: StyleResources,
|
||||
) => {
|
||||
const {injector} = options;
|
||||
|
||||
const dist: any = injector(source, resources);
|
||||
const dist: unknown = injector.call(ctx, source, resources);
|
||||
|
||||
const content = isPromise(dist) ? await dist : dist;
|
||||
const content = await dist;
|
||||
|
||||
if (typeof content !== 'string') {
|
||||
throw new Error(errorMessage.invalidInjectorReturn);
|
||||
|
||||
+8
-6
@@ -1,6 +1,8 @@
|
||||
import {LoaderContext, LoaderCallback} from '..';
|
||||
import type {LoaderContext, LoaderCallback} from '../types';
|
||||
|
||||
import {normalizeOptions, getResources, injectResources} from '.';
|
||||
import {getResources} from './get-resources';
|
||||
import {injectResources} from './inject-resources';
|
||||
import {normalizeOptions} from './normalize-options';
|
||||
|
||||
export const loadResources = async (ctx: LoaderContext, source: string, callback: LoaderCallback) => {
|
||||
try {
|
||||
@@ -8,10 +10,10 @@ export const loadResources = async (ctx: LoaderContext, source: string, callback
|
||||
|
||||
const resources = await getResources(ctx, options);
|
||||
|
||||
const content = await injectResources(options, source, resources);
|
||||
const content = await injectResources(ctx, options, source, resources);
|
||||
|
||||
return callback(null, content);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
callback(null, content);
|
||||
} catch (err: unknown) {
|
||||
callback(err as Error);
|
||||
}
|
||||
};
|
||||
|
||||
+3
-2
@@ -3,10 +3,11 @@ import util from 'util';
|
||||
|
||||
import glob from 'glob';
|
||||
|
||||
import {LoaderContext, StyleResourcesLoaderNormalizedOptions} from '..';
|
||||
import type {LoaderContext, StyleResourcesLoaderNormalizedOptions} from '../types';
|
||||
|
||||
import {isStyleFile} from '.';
|
||||
import {isStyleFile} from './type-guards';
|
||||
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access */
|
||||
const isLegacyWebpack = (ctx: any): ctx is {options: {context: string}} => !!ctx.options;
|
||||
|
||||
const getRootContext = (ctx: LoaderContext) => {
|
||||
|
||||
+4
-4
@@ -2,15 +2,15 @@ import {EOL} from 'os';
|
||||
|
||||
import {getOptions} from 'loader-utils';
|
||||
|
||||
import {
|
||||
import type {
|
||||
LoaderContext,
|
||||
StyleResource,
|
||||
StyleResourcesNormalizedInjector,
|
||||
StyleResourcesLoaderOptions,
|
||||
StyleResourcesLoaderNormalizedOptions,
|
||||
} from '..';
|
||||
} from '../types';
|
||||
|
||||
import {validateOptions} from '.';
|
||||
import {validateOptions} from './validate-options';
|
||||
|
||||
const normalizePatterns = (patterns: StyleResourcesLoaderOptions['patterns']) =>
|
||||
Array.isArray(patterns) ? patterns : [patterns];
|
||||
@@ -31,7 +31,7 @@ const normalizeInjector = (injector: StyleResourcesLoaderOptions['injector']): S
|
||||
};
|
||||
|
||||
export const normalizeOptions = (ctx: LoaderContext): StyleResourcesLoaderNormalizedOptions => {
|
||||
const options = getOptions(ctx) || {};
|
||||
const options = getOptions(ctx);
|
||||
|
||||
validateOptions<StyleResourcesLoaderOptions>(options);
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import path from 'path';
|
||||
|
||||
import {LoaderContext, StyleResource} from '..';
|
||||
import type {LoaderContext, StyleResource} from '../types';
|
||||
|
||||
/* eslint-disable-next-line prefer-named-capture-group */
|
||||
const regex = /@(?:import|require)\s+(?:\([a-z,\s]+\)\s*)?['"]?([^'"\s;]+)['"]?;?/gu;
|
||||
|
||||
+1
-5
@@ -1,11 +1,7 @@
|
||||
import path from 'path';
|
||||
|
||||
import isPromise from 'is-promise';
|
||||
|
||||
import {SUPPORTED_FILE_EXTS} from '.';
|
||||
import {SUPPORTED_FILE_EXTS} from './constants';
|
||||
|
||||
export const isFunction = <T extends (...args: any[]) => any>(arg: any): arg is T => typeof arg === 'function';
|
||||
|
||||
export const isStyleFile = (file: string) => SUPPORTED_FILE_EXTS.includes(path.extname(file));
|
||||
|
||||
export {isPromise};
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
import validate from 'schema-utils';
|
||||
|
||||
import {schema} from '..';
|
||||
import {schema} from '../schema';
|
||||
|
||||
import {LOADER_NAME, VALIDATION_BASE_DATA_PATH} from '.';
|
||||
import {LOADER_NAME, VALIDATION_BASE_DATA_PATH} from './constants';
|
||||
|
||||
export const validateOptions: <T extends {}>(options: any) => asserts options is T = options =>
|
||||
export const validateOptions: <T extends object>(options: object) => asserts options is T = options =>
|
||||
validate(schema, options, {
|
||||
name: LOADER_NAME,
|
||||
baseDataPath: VALIDATION_BASE_DATA_PATH,
|
||||
|
||||
Reference in New Issue
Block a user