Skip to content

Commit

Permalink
chore(weapp-tw): remove all path alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sonofmagic committed Aug 7, 2024
1 parent 792f50c commit 8c37c0c
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 72 deletions.
12 changes: 6 additions & 6 deletions packages/weapp-tailwindcss/src/bundlers/gulp/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import stream from 'node:stream'
import { Buffer } from 'node:buffer'
import type File from 'vinyl'
import { getOptions } from '@/options'
import type { CreateJsHandlerOptions, IStyleHandlerOptions, ITemplateHandlerOptions, UserDefinedOptions } from '@/types'
import { createDebug } from '@/debug'
import { getOptions } from '../../options'
import type { CreateJsHandlerOptions, IStyleHandlerOptions, ITemplateHandlerOptions, UserDefinedOptions } from '../../types'
import { createDebug } from '../../debug'

const debug = createDebug()

Expand All @@ -25,7 +25,7 @@ export function createPlugins(options: UserDefinedOptions = {}) {
function transformWxss(options: Partial<IStyleHandlerOptions> = {}) {
return new Transform({
objectMode: true,
async transform(file: File, encoding, callback) {
async transform(file: File, _encoding, callback) {
runtimeSet = twPatcher.getClassSet()
setMangleRuntimeSet(runtimeSet)
const error = null
Expand Down Expand Up @@ -73,7 +73,7 @@ export function createPlugins(options: UserDefinedOptions = {}) {
function transformJs(options: Partial<CreateJsHandlerOptions> = {}) {
return new Transform({
objectMode: true,
async transform(file: File, encoding, callback) {
async transform(file: File, _encoding, callback) {
const error = null
if (file.contents) {
const rawSource = file.contents.toString()
Expand Down Expand Up @@ -110,7 +110,7 @@ export function createPlugins(options: UserDefinedOptions = {}) {
function transformWxml(options: Partial<ITemplateHandlerOptions> = {}) {
return new Transform({
objectMode: true,
async transform(file: File, encoding, callback) {
async transform(file: File, _encoding, callback) {
const error = null

if (file.contents) {
Expand Down
12 changes: 6 additions & 6 deletions packages/weapp-tailwindcss/src/bundlers/vite/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Plugin } from 'vite'
import type { OutputAsset, OutputChunk } from 'rollup'
import type { UserDefinedOptions } from '@/types'
import { getOptions } from '@/options'
import { vitePluginName } from '@/constants'
import { getGroupedEntries } from '@/utils'
import { createDebug } from '@/debug'
import type { UserDefinedOptions } from '../../types'
import { getOptions } from '../../options'
import { vitePluginName } from '../../constants'
import { getGroupedEntries } from '../../utils'
import { createDebug } from '../../debug'

const debug = createDebug()

Expand Down Expand Up @@ -42,7 +42,7 @@ export function UnifiedViteWeappTailwindcssPlugin(options: UserDefinedOptions =
return {
name: vitePluginName,
enforce: 'post',
async generateBundle(opt, bundle) {
async generateBundle(_opt, bundle) {
debug('start')
onStart()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import path from 'node:path'
import fs from 'node:fs'
import type { Compiler } from 'webpack4'
import { ConcatSource, RawSource } from 'webpack-sources'
import type { AppType, IBaseWebpackPlugin, InternalUserDefinedOptions, UserDefinedOptions } from '@/types'
import { getOptions } from '@/options'
import { pluginName } from '@/constants'
import { getGroupedEntries, removeExt } from '@/utils'
import { createDebug } from '@/debug'
import type { AppType, IBaseWebpackPlugin, InternalUserDefinedOptions, UserDefinedOptions } from '../../../types'
import { getOptions } from '../../../options'
import { pluginName } from '../../../constants'
import { getGroupedEntries, removeExt } from '../../../utils'
import { createDebug } from '../../../debug'

const debug = createDebug()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import path from 'node:path'
import fs from 'node:fs'
import type { Compiler } from 'webpack'
import type { AppType, IBaseWebpackPlugin, InternalUserDefinedOptions, UserDefinedOptions } from '@/types'
import { getOptions } from '@/options'
import { pluginName } from '@/constants'
import { getGroupedEntries, removeExt } from '@/utils'
import { createDebug } from '@/debug'
import type { AppType, IBaseWebpackPlugin, InternalUserDefinedOptions, UserDefinedOptions } from '../../../types'
import { getOptions } from '../../../options'
import { pluginName } from '../../../constants'
import { getGroupedEntries, removeExt } from '../../../utils'
import { createDebug } from '../../../debug'

const debug = createDebug()

Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import process from 'node:process'
import semver from 'semver'
import { getOptions } from '@/options'
import { WEAPP_TW_REQUIRED_NODE_VERSION } from '@/constants'
import { getOptions } from './options'
import { WEAPP_TW_REQUIRED_NODE_VERSION } from './constants'

process.title = 'node (weapp-tailwindcss)'
const args = process.argv.slice(2)
Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getOptions } from '@/options'
import type { CreateJsHandlerOptions, IStyleHandlerOptions, ITemplateHandlerOptions, UserDefinedOptions } from '@/types'
import { getOptions } from './options'
import type { CreateJsHandlerOptions, IStyleHandlerOptions, ITemplateHandlerOptions, UserDefinedOptions } from './types'

export function createContext(options: UserDefinedOptions = {}) {
const opts = getOptions(options)
Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/src/css-macro/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'tailwindcss/types/config'
// import 'tailwindcss/types/config'
import plugin from 'tailwindcss/plugin'
import { createMediaQuery, createNegativeMediaQuery } from './constants'
import { defu } from '@/utils'
Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UserDefinedOptions } from './types'
import { noop } from '@/utils'
import { SimpleMappingChars2String } from '@/escape'
import { noop } from './utils'
import { SimpleMappingChars2String } from './escape'

export const defaultOptions: UserDefinedOptions = {
cssMatcher: file => /.+\.(?:wx|ac|jx|tt|q|c|ty)ss$/.test(file),
Expand Down
10 changes: 5 additions & 5 deletions packages/weapp-tailwindcss/src/js/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// import type { StringLiteral, TemplateElement, Comment } from '@babel/types'
import type MagicString from 'magic-string'
import type { IJsHandlerOptions } from '@/types'
import { replaceWxml } from '@/wxml/shared'
import { escapeStringRegexp } from '@/reg'
import { splitCode } from '@/extractors/split'
import { decodeUnicode2, jsStringEscape } from '@/escape'
import type { IJsHandlerOptions } from '../types'
import { replaceWxml } from '../wxml/shared'
import { escapeStringRegexp } from '../reg'
import { splitCode } from '../extractors/split'
import { decodeUnicode2, jsStringEscape } from '../escape'
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String

interface ReplaceNode {
Expand Down
8 changes: 4 additions & 4 deletions packages/weapp-tailwindcss/src/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { NodePath, TraverseOptions } from '@babel/traverse'
import MagicString from 'magic-string'
import type { ParseError, ParseResult } from '@babel/parser'
import type { SgNode } from '@ast-grep/napi'
import type { CreateJsHandlerOptions, IJsHandlerOptions, JsHandlerResult } from '../types'
import { parse, traverse } from '../babel'
import { jsStringEscape } from '../escape'
import { defuOverrideArray } from '../utils'
import { replaceHandleValue } from './handlers'
import type { CreateJsHandlerOptions, IJsHandlerOptions, JsHandlerResult } from '@/types'
import { parse, traverse } from '@/babel'
import { jsStringEscape } from '@/escape'
import { defuOverrideArray } from '@/utils'

function isEvalPath(p: NodePath<Node>) {
if (p.isCallExpression()) {
Expand Down
6 changes: 3 additions & 3 deletions packages/weapp-tailwindcss/src/mangle/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ClassGenerator, defaultMangleClassFilter } from '@tailwindcss-mangle/shared'
import type { IMangleScopeContext, UserDefinedOptions } from '@/types'
import { splitCode } from '@/extractors/split'
import { escapeStringRegexp } from '@/reg'
import type { IMangleScopeContext, UserDefinedOptions } from '../types'
import { splitCode } from '../extractors/split'
import { escapeStringRegexp } from '../reg'

function getSelf(x: string) {
return x
Expand Down
14 changes: 7 additions & 7 deletions packages/weapp-tailwindcss/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import type {
} from './types'
import { createJsHandler } from './js'
import { defaultOptions } from './defaults'
import { defuOverrideArray, isMap } from '@/utils'
import { createTemplateHandler } from '@/wxml/utils'
import { createStyleHandler } from '@/postcss/index'
import { createInjectPreflight } from '@/postcss/preflight'
import { createTailwindcssPatcher } from '@/tailwindcss/patcher'
import { useMangleStore } from '@/mangle'
import { createCache } from '@/cache'
import { useMangleStore } from './mangle'
import { createCache } from './cache'
import { createStyleHandler } from './postcss/index'
import { createInjectPreflight } from './postcss/preflight'
import { createTemplateHandler } from './wxml/utils'
import { defuOverrideArray, isMap } from './utils'
import { createTailwindcssPatcher } from './tailwindcss/patcher'

export function getOptions(opts?: UserDefinedOptions): InternalUserDefinedOptions {
const result = defuOverrideArray<InternalUserDefinedOptions, Partial<InternalUserDefinedOptions>[]>(
Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/postcss/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import postcss from 'postcss'
import type { IStyleHandlerOptions } from '../types'
import { defuOverrideArray } from '../utils'
import { getPlugins } from './plugins'
import type { IStyleHandlerOptions } from '@/types'
import { defuOverrideArray } from '@/utils'

export async function styleHandler(rawSource: string, options: IStyleHandlerOptions) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/src/postcss/mp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Declaration, Rule } from 'postcss'
import type { IStyleHandlerOptions } from '../types'
import { isOnlyBeforeAndAfterPseudoElement } from './selectorParser'
import cssVars from './cssVars'
import { composeIsPseudo } from './shared'
import type { IStyleHandlerOptions } from '@/types'

const initialNodes = cssVars.map((x) => {
return new Declaration({
Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/src/postcss/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { AcceptedPlugin } from 'postcss'
// @ts-expect-error
import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class'
import postcssRem2rpx from 'postcss-rem-to-responsive-pixel'
import type { IStyleHandlerOptions } from '../../types'
import { postcssWeappTailwindcssPrePlugin } from './pre'
import { postcssWeappTailwindcssPostPlugin } from './post'
import { createContext } from './ctx'
import type { IStyleHandlerOptions } from '@/types'

export function getPlugins(options: IStyleHandlerOptions) {
const ctx = createContext()
Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/postcss/plugins/post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Plugin, PluginCreator } from 'postcss'
import { testIfVariablesScope } from '../mp'
import { fallbackRemove } from '../selectorParser'
import type { IStyleHandlerOptions } from '@/types'
import { postcssPlugin } from '@/constants'
import type { IStyleHandlerOptions } from '../../types'
import { postcssPlugin } from '../../constants'

export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>

Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/postcss/plugins/pre.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AtRule, Plugin, PluginCreator } from 'postcss'
import { ruleTransformSync } from '../selectorParser'
import { commonChunkPreflight } from '../mp'
import type { IStyleHandlerOptions } from '@/types'
import { postcssPlugin } from '@/constants'
import type { IStyleHandlerOptions } from '../../types'
import { postcssPlugin } from '../../constants'

export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>

Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/src/postcss/preflight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CssPreflightOptions, IPropValue } from '@/types'
import type { CssPreflightOptions, IPropValue } from '../types'

export type InjectPreflight = () => IPropValue[]

Expand Down
6 changes: 4 additions & 2 deletions packages/weapp-tailwindcss/src/postcss/selectorParser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import selectorParser from 'postcss-selector-parser'
import type { SyncProcessor } from 'postcss-selector-parser'
import type { Rule } from 'postcss'
import type { IStyleHandlerOptions } from '../types'
import { composeIsPseudo, internalCssSelectorReplacer } from './shared'
import type { IStyleHandlerOptions } from '@/types'

function createRuleTransform(rule: Rule, options: IStyleHandlerOptions) {
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options
Expand All @@ -17,7 +17,9 @@ function createRuleTransform(rule: Rule, options: IStyleHandlerOptions) {

if (cssRemoveHoverPseudoClass && selector.type === 'selector') {
const node = selector.nodes.find(x => x.type === 'pseudo' && x.value === ':hover')
node && selector.remove()
if (node) {
selector.remove()
}
}

if (
Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/postcss/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SimpleMappingChars2String, escape } from '@/escape'
import type { InternalCssSelectorReplacerOptions } from '@/types'
import { SimpleMappingChars2String, escape } from '../escape'
import type { InternalCssSelectorReplacerOptions } from '../types'
// css 中,要多加一个 '\' 来转义
// for raw css selector
// export function cssSelectorReplacer(selector: string, escapeEntries = MappingChars2StringEntries) {
Expand Down
2 changes: 1 addition & 1 deletion packages/weapp-tailwindcss/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Result } from 'postcss-load-config'
import type { ILengthUnitsPatchOptions, TailwindcssPatcher } from 'tailwindcss-patch'
import type { InjectPreflight } from './postcss/preflight'
import type { IContext as PostcssContext } from './postcss/plugins/ctx'
import type { ICreateCacheReturnType } from '@/cache'
import type { ICreateCacheReturnType } from './cache'

type PostcssOptions = Partial<Omit<Result, 'file'>>

Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createDefu } from 'defu'
// import type { Defu } from 'defu'
import type { InternalUserDefinedOptions } from '@/types'
import type { InternalUserDefinedOptions } from './types'

export function isRegexp(value: unknown) {
return Object.prototype.toString.call(value) === '[object RegExp]'
Expand Down Expand Up @@ -29,7 +29,7 @@ export function regExpTest(arr: (string | RegExp)[] = [], str: string) {
throw new TypeError('paramater \'arr\' should be a Array of Regexp | String !')
}

export function noop() {}
export function noop() { }

// const MAX_ASCII_CHAR_CODE = 127

Expand Down
4 changes: 2 additions & 2 deletions packages/weapp-tailwindcss/src/wxml/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ITemplateHandlerOptions } from '@/types'
import { SimpleMappingChars2String, escape } from '@/escape'
import type { ITemplateHandlerOptions } from '../types'
import { SimpleMappingChars2String, escape } from '../escape'

export function replaceWxml(
original: string,
Expand Down
12 changes: 6 additions & 6 deletions packages/weapp-tailwindcss/src/wxml/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as t from '@babel/types'
import { Parser } from 'htmlparser2'
import MagicString from 'magic-string'
import { parseExpression, traverse } from '../babel'
import type { ItemOrItemArray } from '../reg'
import { variableRegExp } from '../reg'
import { defuOverrideArray } from '../utils'
import type { ITemplateHandlerOptions, RawSource } from '../types'
import { replaceHandleValue } from '../js/handlers'
import { replaceWxml } from './shared'
import type { Token } from './Tokenizer'
import { Tokenizer } from './Tokenizer'
import { parseExpression, traverse } from '@/babel'
import type { ItemOrItemArray } from '@/reg'
import { variableRegExp } from '@/reg'
import { defuOverrideArray } from '@/utils'
import type { ITemplateHandlerOptions, RawSource } from '@/types'
import { replaceHandleValue } from '@/js/handlers'

export function generateCode(match: string, options: ITemplateHandlerOptions = {}) {
try {
Expand Down

0 comments on commit 8c37c0c

Please sign in to comment.