Skip to content

Commit

Permalink
chore: release v0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Dec 23, 2024
1 parent 715ef68 commit 87e5687
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 78 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-plugin/src/ast/evaluate-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ export function printCssAST(data: ReturnType<typeof sortAndMergeEvaluatedResult>
) {
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)
}
Expand Down
83 changes: 13 additions & 70 deletions packages/babel-plugin/src/module.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -169,45 +151,6 @@ function matchFileSuffix(allowedSuffix: string) {

export type PathResolverOptions = Pick<StylexExtendBabelPluginOptions, 'unstable_moduleResolution' | 'aliases'>

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

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 87e5687

Please sign in to comment.