diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc674d..4435771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.5.2 (2024-12-23) + +- Synchronize official changes to `rootdir`. + ## v0.5.1 (2024-12-21) - Fix `vite-plugin` error regexp. diff --git a/package.json b/package.json index 28cb5de..fce2fce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stylex-extend", "description": "An unofficial stylexjs extension", - "version": "0.5.1", + "version": "0.5.2", "scripts": { "test": "pnpm -r run test" }, diff --git a/packages/babel-plugin/package.json b/packages/babel-plugin/package.json index be537b5..d2f598b 100644 --- a/packages/babel-plugin/package.json +++ b/packages/babel-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@stylex-extend/babel-plugin", - "version": "0.5.1", + "version": "0.5.2", "description": "A friendly stylex babel plugin extension.", "module": "./dist/index.mjs", "main": "./dist/index.js", diff --git a/packages/babel-plugin/src/ast/evaluate-path.ts b/packages/babel-plugin/src/ast/evaluate-path.ts index 33c7b54..c359899 100644 --- a/packages/babel-plugin/src/ast/evaluate-path.ts +++ b/packages/babel-plugin/src/ast/evaluate-path.ts @@ -370,8 +370,9 @@ export function printCssAST(data: ReturnType ) { const importSpecifierPath = bindingPath const imported = importSpecifierPath.node.imported + // Note: This implementation is consistent with the official. const importDeclaration = findNearestParentWithCondition(importSpecifierPath, isImportDeclaration) - const hashing = mod.fileNameForHashing(importDeclaration.node.source.value + '.ts') + const hashing = mod.fileNameForHashing(importDeclaration.node.source.value) if (!hashing) { throw new Error(MESSAGES.NO_STATIC_ATTRIBUTE) } diff --git a/packages/babel-plugin/src/module.ts b/packages/babel-plugin/src/module.ts index 14bccb0..5f95382 100644 --- a/packages/babel-plugin/src/module.ts +++ b/packages/babel-plugin/src/module.ts @@ -1,5 +1,5 @@ import type { NodePath, PluginPass as BabelPluginPass, types } from '@babel/core' -import { resolve as esmResolve } from '@dual-bundle/import-meta-resolve' +import { moduleResolve } from '@dual-bundle/import-meta-resolve' import fs from 'fs' import path from 'path' import url from 'url' @@ -66,7 +66,7 @@ export class Module { fileNameForHashing(relativePath: string) { const fileName = filePathResolver(relativePath, this.filename, this.options.aliases) - + console.log('fileNameForHashing', fileName) const { themeFileExtension = '.stylex', type } = this.options.unstable_moduleResolution ?? {} if (!fileName || !matchFileSuffix(themeFileExtension!)(fileName) || this.options.unstable_moduleResolution == null) { return null @@ -117,38 +117,20 @@ function filePathResolver(relativeFilePath: string, sourceFilePath: string, alia for (const ext of ['', ...FILE_EXTENSIONS]) { const importPathStr = relativeFilePath + ext - // Try to resolve relative paths as is - if (importPathStr.startsWith('.')) { + if (relativeFilePath[0] === '.') { try { - return require.resolve(importPathStr, { - paths: [path.dirname(sourceFilePath)] - }) + return moduleResolve(importPathStr, url.pathToFileURL(sourceFilePath)).pathname } catch { - const resolved = url.fileURLToPath(esmResolve(importPathStr, import.meta.url)) - if (resolved) { - if (resolved.startsWith('.')) { - return path.resolve(path.dirname(sourceFilePath), resolved) - } - return resolved - } + continue } - } - - // Otherwise, try to resolve the path with aliases - const allAliases = possibleAliasedPaths(importPathStr, aliases) - for (const possiblePath of allAliases) { - try { - return require.resolve(possiblePath, { - paths: [path.dirname(sourceFilePath)] - }) - } catch { - const resolved = esmResolve(importPathStr, import.meta.url) - - if (resolved) { - if (resolved.startsWith('.')) { - return path.resolve(path.dirname(sourceFilePath), resolved) - } - return resolved + } else { + const allAliases = possibleAliasedPaths(importPathStr, aliases) + // Otherwise, try to resolve the path with aliases + for (const possiblePath of allAliases) { + try { + return moduleResolve(possiblePath, url.pathToFileURL(sourceFilePath)).pathname + } catch { + continue } } } @@ -169,45 +151,6 @@ function matchFileSuffix(allowedSuffix: string) { export type PathResolverOptions = Pick -export function importPathResolver(importPath: string, fileName: string, options: PathResolverOptions) { - if (!fileName) { return false } - switch (options.unstable_moduleResolution?.type) { - case 'commonJS': { - const { aliases } = options - const { themeFileExtension = '.stylex', rootDir } = options.unstable_moduleResolution - if (!matchFileSuffix(themeFileExtension!)(importPath)) { return false } - const resolvedFilePath = filePathResolver( - importPath, - fileName, - aliases - ) - return resolvedFilePath - ? ['themeNameRef', getCanonicalFilePath(resolvedFilePath, rootDir)] - : false - } - case 'haste': { - const { themeFileExtension = '.stylex' } = options.unstable_moduleResolution - if (!matchFileSuffix(themeFileExtension!)(importPath)) { - return false - } - return ['themeNameRef', addFileExtension(importPath, fileName)] - } - case 'experimental_crossFileParsing': { - const { aliases } = options - const { themeFileExtension = '.stylex' } = options.unstable_moduleResolution - if (!matchFileSuffix(themeFileExtension!)(importPath)) { return false } - const resolvedFilePath = filePathResolver( - importPath, - fileName, - aliases - ) - return resolvedFilePath ? ['filePath', resolvedFilePath] : false - } - default: - return false - } -} - // Path: https://github.com/facebook/stylex/blob/main/packages/babel-plugin/src/utils/state-manager.js // After 0.9.0 this is live diff --git a/packages/core/package.json b/packages/core/package.json index c62bf63..606a560 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,7 +3,7 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "module": "dist/index.mjs", - "version": "0.5.1", + "version": "0.5.2", "license": "MIT", "repository": "https://github.com/nonzzz/stylex-extend.git", "scripts": { diff --git a/packages/react/package.json b/packages/react/package.json index b9318e0..0e3497a 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -3,7 +3,7 @@ "main": "./src/index.js", "module": "./src/index.js", "types": "./src/index.d.ts", - "version": "0.5.1", + "version": "0.5.2", "repository": "https://github.com/nonzzz/stylex-extend.git", "license": "MIT", "devDependencies": { diff --git a/packages/shared/package.json b/packages/shared/package.json index 34f5a1f..5417ae9 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,7 +1,7 @@ { "name": "@stylex-extend/shared", "description": "Shared utilities for StyleX Extend", - "version": "0.5.1", + "version": "0.5.2", "license": "MIT", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/packages/vite/package.json b/packages/vite/package.json index de998d7..75ae422 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "@stylex-extend/vite", - "version": "0.5.1", + "version": "0.5.2", "main": "./dist/index.js", "module": "./dist/index.mjs", "files": [ diff --git a/packages/vue/package.json b/packages/vue/package.json index 229fec6..326468a 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -3,7 +3,7 @@ "main": "./index.js", "module": "./index.js", "types": "./index.d.ts", - "version": "0.5.1", + "version": "0.5.2", "license": "MIT", "repository": "https://github.com/nonzzz/stylex-extend.git", "devDependencies": {