update
This commit is contained in:
+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