mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-19 01:36:46 +08:00
@@ -1,5 +1,5 @@
|
|||||||
import micromatch from "micromatch";
|
import micromatch from "micromatch";
|
||||||
import { join, isAbsolute } from "node:path";
|
import { resolve, sep, posix } from "node:path";
|
||||||
import { TailwindConfig } from "tailwindcss/tailwind-config";
|
import { TailwindConfig } from "tailwindcss/tailwind-config";
|
||||||
import { TailwindcssReactNativeBabelOptions, AllowPathOptions } from "../types";
|
import { TailwindcssReactNativeBabelOptions, AllowPathOptions } from "../types";
|
||||||
|
|
||||||
@@ -43,9 +43,19 @@ export function isAllowedProgramPath({
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is my naive way to get path matching working on Windows.
|
||||||
|
* Basically I turn it into a posix path which seems to work fine
|
||||||
|
*
|
||||||
|
* If you are a windows user and understand micromatch, can you please send a PR
|
||||||
|
* to do this the proper way
|
||||||
|
*/
|
||||||
|
const posixPath = path.split(sep).join(posix.sep);
|
||||||
|
|
||||||
return allowRelativeModules.some((modulePath) => {
|
return allowRelativeModules.some((modulePath) => {
|
||||||
return isAbsolute(modulePath)
|
return micromatch.isMatch(
|
||||||
? micromatch.isMatch(path, modulePath)
|
posixPath,
|
||||||
: micromatch.isMatch(path, join(cwd, modulePath));
|
resolve(cwd, modulePath).split(sep).join(posix.sep)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createRequire } from "node:module";
|
import { createRequire } from "node:module";
|
||||||
import { join, dirname, basename, resolve } from "node:path";
|
import { join, dirname, basename, resolve, sep, posix } from "node:path";
|
||||||
import { readdirSync, lstatSync, existsSync } from "node:fs";
|
import { readdirSync, lstatSync, existsSync } from "node:fs";
|
||||||
import micromatch from "micromatch";
|
import micromatch from "micromatch";
|
||||||
|
|
||||||
@@ -88,11 +88,24 @@ export function getImportBlockedComponents(
|
|||||||
} else {
|
} else {
|
||||||
const normalizedAllowRelativeModules = !Array.isArray(allowRelativeModules)
|
const normalizedAllowRelativeModules = !Array.isArray(allowRelativeModules)
|
||||||
? []
|
? []
|
||||||
: allowRelativeModules.map((modulePath) => resolve(cwd, modulePath));
|
: allowRelativeModules.map((modulePath) =>
|
||||||
|
resolve(cwd, modulePath).split(sep).join(posix.sep)
|
||||||
|
);
|
||||||
|
|
||||||
const isNotAllowedRelative = !modulePaths.some((modulePath) =>
|
const isNotAllowedRelative = !modulePaths.some((modulePath) => {
|
||||||
micromatch.isMatch(modulePath, normalizedAllowRelativeModules)
|
/**
|
||||||
);
|
* This is my naive way to get path matching working on Windows.
|
||||||
|
* Basically I turn it into a posix path which seems to work fine
|
||||||
|
*
|
||||||
|
* If you are a windows user and understand micromatch, can you please send a PR
|
||||||
|
* to do this the proper way
|
||||||
|
*/
|
||||||
|
const posixModulePath = modulePath.split(sep).join(posix.sep);
|
||||||
|
return micromatch.isMatch(
|
||||||
|
posixModulePath,
|
||||||
|
normalizedAllowRelativeModules
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
returnComponentsAsBlocked = isNotAllowedRelative;
|
returnComponentsAsBlocked = isNotAllowedRelative;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user