Skip to content

Commit

Permalink
v2.2.5 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
indooorsman authored Mar 22, 2022
1 parent 3c51f87 commit ba1ef52
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 175 deletions.
18 changes: 17 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'esbuild';
import type { Plugin, PluginBuild } from 'esbuild';

declare type GenerateScopedNameFunction = (name: string, filename: string, css: string) => string;

Expand Down Expand Up @@ -47,12 +47,28 @@ declare interface PluginOptions {
generateScopedName?: CssModulesOptions['generateScopedName'];
cssModulesOption?: CssModulesOptions;
v2?: boolean;
root?: string;
package?: {
name: string,
main?: string,
module?: string,
version?: string
}
}

declare interface BuildContext {
buildId: string;
buildRoot: string;
packageRoot?: string;
}

declare function CssModulesPlugin(options?: PluginOptions): Plugin;

declare namespace CssModulesPlugin {
export type Options = PluginOptions;
export interface Build extends PluginBuild {
context: BuildContext;
}
}

export = CssModulesPlugin;
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const { pluginName } = require('./lib/utils');
const CssModulesPlugin = (options = {}) => {
return {
name: pluginName,
setup(build) {
setup: async (build) => {
const { bundle } = build.initialOptions;
const { v2 } = options;
const useV2 = v2 && bundle;

if (useV2) {
plugin.setup(build, options);
await plugin.setup(build, options);
} else {
pluginV1.setup(build, options);
await pluginV1.setup(build, options);
}
}
};
Expand Down
17 changes: 17 additions & 0 deletions lib/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const cacheHolder = { cache: new Map() };

module.exports = {
get(key) {
const ref = cacheHolder.cache.get(key);
if (ref) {
return ref.deref();
}
},
set(key, data) {
const wr = new WeakRef(data);
cacheHolder.cache.set(key, wr);
},
clear() {
cacheHolder.cache.clear();
}
};
Loading

0 comments on commit ba1ef52

Please sign in to comment.