@weapp-tailwindcss/merge 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/postinstall.cjs +8 -1
- package/dist/postinstall.js +8 -1
- package/package.json +2 -2
- package/scripts/postinstall.mjs +83 -0
- package/scripts/postinstall.cjs +0 -15
package/dist/postinstall.cjs
CHANGED
|
@@ -147,7 +147,14 @@ function ensureVariant(distDir, variant) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
function main() {
|
|
150
|
-
const
|
|
150
|
+
const resolveDistDir = () => {
|
|
151
|
+
if (typeof __dirname === "string") {
|
|
152
|
+
return _path2.default.resolve(__dirname, "../dist");
|
|
153
|
+
}
|
|
154
|
+
const getImportMetaUrl = new Function("return import.meta.url");
|
|
155
|
+
return _url.fileURLToPath.call(void 0, new URL("../dist/", getImportMetaUrl()));
|
|
156
|
+
};
|
|
157
|
+
const distDir = resolveDistDir();
|
|
151
158
|
if (!_fs2.default.existsSync(distDir)) {
|
|
152
159
|
warn("dist directory not found. Skipping runtime switch.");
|
|
153
160
|
return;
|
package/dist/postinstall.js
CHANGED
|
@@ -147,7 +147,14 @@ function ensureVariant(distDir, variant) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
function main() {
|
|
150
|
-
const
|
|
150
|
+
const resolveDistDir = () => {
|
|
151
|
+
if (typeof __dirname === "string") {
|
|
152
|
+
return path.resolve(__dirname, "../dist");
|
|
153
|
+
}
|
|
154
|
+
const getImportMetaUrl = new Function("return import.meta.url");
|
|
155
|
+
return fileURLToPath(new URL("../dist/", getImportMetaUrl()));
|
|
156
|
+
};
|
|
157
|
+
const distDir = resolveDistDir();
|
|
151
158
|
if (!fs.existsSync(distDir)) {
|
|
152
159
|
warn("dist directory not found. Skipping runtime switch.");
|
|
153
160
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/merge",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "weapp-tailwindcss",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -73,6 +73,6 @@
|
|
|
73
73
|
"release": "pnpm publish",
|
|
74
74
|
"lint": "eslint .",
|
|
75
75
|
"lint:fix": "eslint . --fix",
|
|
76
|
-
"postinstall": "node scripts/postinstall.
|
|
76
|
+
"postinstall": "node scripts/postinstall.mjs"
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync as defaultExistsSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import process from 'node:process'
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const requireFn = createRequire(import.meta.url)
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {object} [options]
|
|
12
|
+
* @param {(path: string) => boolean} [options.existsSync]
|
|
13
|
+
* @param {(path: string) => Promise<unknown>} [options.loadEsm]
|
|
14
|
+
* @param {(path: string) => unknown | Promise<unknown>} [options.loadCjs]
|
|
15
|
+
* @param {{ log: typeof console.log, error: typeof console.error }} [options.logger]
|
|
16
|
+
*/
|
|
17
|
+
export async function run(options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
existsSync = defaultExistsSync,
|
|
20
|
+
loadEsm = async filePath => import(pathToFileURL(filePath).href),
|
|
21
|
+
loadCjs = filePath => requireFn(filePath),
|
|
22
|
+
logger = console,
|
|
23
|
+
} = options
|
|
24
|
+
|
|
25
|
+
const esmPath = path.resolve(__dirname, '../dist/postinstall.js')
|
|
26
|
+
const cjsPath = path.resolve(__dirname, '../dist/postinstall.cjs')
|
|
27
|
+
|
|
28
|
+
const hasEsm = existsSync(esmPath)
|
|
29
|
+
const hasCjs = existsSync(cjsPath)
|
|
30
|
+
|
|
31
|
+
const loadErrors = []
|
|
32
|
+
|
|
33
|
+
if (hasEsm) {
|
|
34
|
+
try {
|
|
35
|
+
await loadEsm(esmPath)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
loadErrors.push(error)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (hasCjs) {
|
|
44
|
+
try {
|
|
45
|
+
await loadCjs(cjsPath)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
loadErrors.push(error)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!hasEsm && !hasCjs) {
|
|
54
|
+
logger.log('postinstall bundle not found')
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
logger.error('Failed to load postinstall bundle.')
|
|
59
|
+
for (const error of loadErrors) {
|
|
60
|
+
logger.error(error)
|
|
61
|
+
}
|
|
62
|
+
process.exitCode = process.exitCode ?? 1
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const entryUrl = (() => {
|
|
66
|
+
const candidate = process.argv[1]
|
|
67
|
+
if (!candidate) {
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return pathToFileURL(candidate).href
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined
|
|
75
|
+
}
|
|
76
|
+
})()
|
|
77
|
+
|
|
78
|
+
if (entryUrl === import.meta.url) {
|
|
79
|
+
run().catch((error) => {
|
|
80
|
+
console.error('Failed to execute postinstall entry.', error)
|
|
81
|
+
process.exitCode = process.exitCode ?? 1
|
|
82
|
+
})
|
|
83
|
+
}
|
package/scripts/postinstall.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/* eslint-disable ts/no-require-imports */
|
|
2
|
-
const fs = require('node:fs')
|
|
3
|
-
const path = require('node:path')
|
|
4
|
-
|
|
5
|
-
function main() {
|
|
6
|
-
const targetPath = path.resolve(__dirname, '../dist/postinstall.cjs')
|
|
7
|
-
if (fs.existsSync(targetPath)) {
|
|
8
|
-
require(targetPath)
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
console.log('postinstall.cjs not found')
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
main()
|