mirror of
https://github.com/iconify/iconify.git
synced 2024-11-14 00:34:04 +00:00
chore: move node stuff + package.json changes
This commit is contained in:
parent
0a8a0c9a23
commit
7ba8d5a2be
@ -25,8 +25,9 @@ export default defineBuildConfig({
|
|||||||
{ input: 'src/loader/fs', name: 'loader/fs' },
|
{ input: 'src/loader/fs', name: 'loader/fs' },
|
||||||
{ input: 'src/loader/install-pkg', name: 'loader/install-pkg' },
|
{ input: 'src/loader/install-pkg', name: 'loader/install-pkg' },
|
||||||
{ input: 'src/loader/loader', name: 'loader/loader' },
|
{ input: 'src/loader/loader', name: 'loader/loader' },
|
||||||
{ input: 'src/loader/loaders', name: 'loader/loaders' },
|
|
||||||
{ input: 'src/loader/modern', name: 'loader/modern' },
|
{ input: 'src/loader/modern', name: 'loader/modern' },
|
||||||
|
{ input: 'src/loader/node-loader', name: 'loader/node-loader' },
|
||||||
|
{ input: 'src/loader/node-loaders', name: 'loader/node-loaders' },
|
||||||
{ input: 'src/loader/types', name: 'loader/types' },
|
{ input: 'src/loader/types', name: 'loader/types' },
|
||||||
{ input: 'src/loader/utils', name: 'loader/utils' },
|
{ input: 'src/loader/utils', name: 'loader/utils' },
|
||||||
{ input: 'src/loader/warn', name: 'loader/warn' },
|
{ input: 'src/loader/warn', name: 'loader/warn' },
|
||||||
|
7
packages/utils/jest.cjs.config.ts
Normal file
7
packages/utils/jest.cjs.config.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
verbose: true,
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/tests/*-test.ts'],
|
||||||
|
};
|
7
packages/utils/jest.esm.config.ts
Normal file
7
packages/utils/jest.esm.config.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
verbose: true,
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/tests/*-test.ts'],
|
||||||
|
};
|
@ -22,9 +22,8 @@
|
|||||||
"test:jasmine": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jasmine",
|
"test:jasmine": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jasmine",
|
||||||
"test": "npm run test:jest && npm run test:jasmine"
|
"test": "npm run test:jest && npm run test:jasmine"
|
||||||
},
|
},
|
||||||
"sideEffects": "false",
|
"sideEffects": false,
|
||||||
"exports": {
|
"exports": {
|
||||||
"./*": "./*",
|
|
||||||
".": {
|
".": {
|
||||||
"require": "./lib/index.cjs",
|
"require": "./lib/index.cjs",
|
||||||
"import": "./lib/index.mjs"
|
"import": "./lib/index.mjs"
|
||||||
@ -139,15 +138,20 @@
|
|||||||
"require": "./lib/loader/loader.cjs",
|
"require": "./lib/loader/loader.cjs",
|
||||||
"import": "./lib/loader/loader.mjs"
|
"import": "./lib/loader/loader.mjs"
|
||||||
},
|
},
|
||||||
"./lib/loader/loaders": {
|
|
||||||
"require": "./lib/loader/loaders.cjs",
|
|
||||||
"import": "./lib/loader/loaders.mjs",
|
|
||||||
"types": "./lib/loader/loaders.d.ts"
|
|
||||||
},
|
|
||||||
"./lib/loader/modern": {
|
"./lib/loader/modern": {
|
||||||
"require": "./lib/loader/modern.cjs",
|
"require": "./lib/loader/modern.cjs",
|
||||||
"import": "./lib/loader/modern.mjs"
|
"import": "./lib/loader/modern.mjs"
|
||||||
},
|
},
|
||||||
|
"./lib/loader/node-loader": {
|
||||||
|
"require": "./lib/loader/node-loader.cjs",
|
||||||
|
"import": "./lib/loader/node-loader.mjs",
|
||||||
|
"types": "./lib/loader/node-loader.d.ts"
|
||||||
|
},
|
||||||
|
"./lib/loader/node-loaders": {
|
||||||
|
"require": "./lib/loader/node-loaders.cjs",
|
||||||
|
"import": "./lib/loader/node-loaders.mjs",
|
||||||
|
"types": "./lib/loader/node-loaders.d.ts"
|
||||||
|
},
|
||||||
"./lib/loader/types": {
|
"./lib/loader/types": {
|
||||||
"require": "./lib/loader/types.cjs",
|
"require": "./lib/loader/types.cjs",
|
||||||
"import": "./lib/loader/types.mjs"
|
"import": "./lib/loader/types.mjs"
|
||||||
@ -180,11 +184,23 @@
|
|||||||
"./lib/svg/size": {
|
"./lib/svg/size": {
|
||||||
"require": "./lib/svg/size.cjs",
|
"require": "./lib/svg/size.cjs",
|
||||||
"import": "./lib/svg/size.mjs"
|
"import": "./lib/svg/size.mjs"
|
||||||
}
|
},
|
||||||
|
"./*": "./*"
|
||||||
},
|
},
|
||||||
"main": "./lib/index.cjs",
|
"main": "lib/index.cjs",
|
||||||
"module": "./lib/index.mjs",
|
"module": "lib/index.mjs",
|
||||||
"types": "./lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"lib/colors",
|
||||||
|
"lib/customisations",
|
||||||
|
"lib/icon",
|
||||||
|
"lib/icon-set",
|
||||||
|
"lib/loader",
|
||||||
|
"lib/misc",
|
||||||
|
"lib/svg",
|
||||||
|
"*.d.ts"
|
||||||
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@antfu/install-pkg": "^0.1.0",
|
"@antfu/install-pkg": "^0.1.0",
|
||||||
"@antfu/utils": "^0.3.0",
|
"@antfu/utils": "^0.3.0",
|
||||||
|
@ -53,11 +53,12 @@ export type {
|
|||||||
IconCustomizations,
|
IconCustomizations,
|
||||||
IconifyLoaderOptions,
|
IconifyLoaderOptions,
|
||||||
InlineCollection,
|
InlineCollection,
|
||||||
|
UniversalIconLoader,
|
||||||
} from './loader/types';
|
} from './loader/types';
|
||||||
export { mergeIconProps } from './loader/utils';
|
export { mergeIconProps } from './loader/utils';
|
||||||
export { getCustomIcon } from './loader/custom';
|
export { getCustomIcon } from './loader/custom';
|
||||||
export { searchForIcon } from './loader/modern';
|
export { searchForIcon } from './loader/modern';
|
||||||
export { isNode, loadIcon } from './loader/loader';
|
export { loadIcon } from './loader/loader';
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
export { camelize, camelToKebab, snakelize, pascalize } from './misc/strings';
|
export { camelize, camelToKebab, snakelize, pascalize } from './misc/strings';
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import { getCustomIcon } from './custom';
|
import { getCustomIcon } from './custom';
|
||||||
import type { IconifyLoaderOptions } from './types';
|
import type { UniversalIconLoader } from './types';
|
||||||
import { searchForIcon } from './modern';
|
import { searchForIcon } from './modern';
|
||||||
|
|
||||||
export const isNode = typeof process < 'u' && typeof process.stdout < 'u';
|
export const loadIcon: UniversalIconLoader = async(
|
||||||
|
collection,
|
||||||
export async function loadIcon(
|
icon,
|
||||||
collection: string,
|
options
|
||||||
icon: string,
|
) => {
|
||||||
options?: IconifyLoaderOptions
|
|
||||||
): Promise<string | undefined> {
|
|
||||||
const custom = options?.customCollections?.[collection];
|
const custom = options?.customCollections?.[collection];
|
||||||
|
|
||||||
if (custom) {
|
if (custom) {
|
||||||
@ -35,67 +33,5 @@ export async function loadIcon(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNode) {
|
return undefined;
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await loadNodeBuiltinIcon(collection, icon, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function importFsModule(): Promise<typeof import('./fs') | undefined> {
|
|
||||||
try {
|
|
||||||
return await import('./fs');
|
|
||||||
} catch {
|
|
||||||
try {
|
|
||||||
// cjs environments
|
|
||||||
return require('./fs.cjs');
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importWarnModule(): Promise<typeof import('./warn') | undefined> {
|
|
||||||
try {
|
|
||||||
return await import('./warn');
|
|
||||||
} catch {
|
|
||||||
try {
|
|
||||||
// cjs environments
|
|
||||||
return require('./warn.cjs');
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadNodeBuiltinIcon(
|
|
||||||
collection: string,
|
|
||||||
icon: string,
|
|
||||||
options?: IconifyLoaderOptions,
|
|
||||||
): Promise<string | undefined> {
|
|
||||||
let result: string | undefined;
|
|
||||||
const loadCollectionFromFS = await importFsModule().then(i => i?.loadCollectionFromFS);
|
|
||||||
if (loadCollectionFromFS) {
|
|
||||||
const iconSet = await loadCollectionFromFS(collection, options?.autoInstall);
|
|
||||||
if (iconSet) {
|
|
||||||
// possible icon names
|
|
||||||
const ids = [
|
|
||||||
icon,
|
|
||||||
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
|
||||||
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
|
||||||
];
|
|
||||||
result = await searchForIcon(iconSet, collection, ids, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result && options?.warn) {
|
|
||||||
const warnOnce = await importWarnModule().then(i => i?.warnOnce);
|
|
||||||
warnOnce?.(`failed to load ${options.warn} icon`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
34
packages/utils/src/loader/node-loader.ts
Normal file
34
packages/utils/src/loader/node-loader.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import type { UniversalIconLoader } from './types';
|
||||||
|
import { searchForIcon } from './modern';
|
||||||
|
import { loadCollectionFromFS } from './fs';
|
||||||
|
import { warnOnce } from './warn';
|
||||||
|
import { loadIcon } from './loader';
|
||||||
|
|
||||||
|
export const loadNodeIcon: UniversalIconLoader = async(
|
||||||
|
collection,
|
||||||
|
icon,
|
||||||
|
options,
|
||||||
|
) => {
|
||||||
|
let result = await loadIcon(collection, icon, options);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const iconSet = await loadCollectionFromFS(collection, options?.autoInstall);
|
||||||
|
if (iconSet) {
|
||||||
|
// possible icon names
|
||||||
|
const ids = [
|
||||||
|
icon,
|
||||||
|
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
||||||
|
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
||||||
|
];
|
||||||
|
result = await searchForIcon(iconSet, collection, ids, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result && options?.warn) {
|
||||||
|
warnOnce(`failed to load ${options.warn} icon`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,15 @@ import type { Awaitable } from '@antfu/utils';
|
|||||||
import type { FullIconCustomisations } from '../customisations';
|
import type { FullIconCustomisations } from '../customisations';
|
||||||
import type { IconifyJSON } from '@iconify/types';
|
import type { IconifyJSON } from '@iconify/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type for universal icon loader.
|
||||||
|
*/
|
||||||
|
export type UniversalIconLoader = (
|
||||||
|
collection: string,
|
||||||
|
icon: string,
|
||||||
|
options?: IconifyLoaderOptions
|
||||||
|
) => Promise<string | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom icon loader, used by `getCustomIcon`.
|
* Custom icon loader, used by `getCustomIcon`.
|
||||||
*/
|
*/
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
"DOM"
|
"DOM"
|
||||||
],
|
],
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"importsNotUsedAsValues": "error"
|
"importsNotUsedAsValues": "error"
|
||||||
},
|
},
|
||||||
"include": ["./src/**/*.ts"]
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user