@dcloudio/uni-cli-shared 3.0.0-alpha-3030220211217008 → 3.0.0-alpha-3030220211217009
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Plugin } from '../plugin';
|
|
3
3
|
import { ResolvedConfig } from '../config';
|
|
4
|
-
import { PluginContext, RenderedChunk } from 'rollup';
|
|
4
|
+
import type { OutputOptions, PluginContext, RenderedChunk } from 'rollup';
|
|
5
5
|
export declare const assetUrlRE: RegExp;
|
|
6
6
|
export declare const chunkToEmittedAssetsMap: WeakMap<RenderedChunk, Set<string>>;
|
|
7
7
|
/**
|
|
@@ -12,5 +12,29 @@ export declare function registerAssetToChunk(chunk: RenderedChunk, file: string)
|
|
|
12
12
|
export declare function checkPublicFile(url: string, { publicDir }: ResolvedConfig): string | undefined;
|
|
13
13
|
export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext, canInline?: boolean): string;
|
|
14
14
|
export declare function getAssetFilename(hash: string, config: ResolvedConfig): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* converts the source filepath of the asset to the output filename based on the assetFileNames option. \
|
|
17
|
+
* this function imitates the behavior of rollup.js. \
|
|
18
|
+
* https://rollupjs.org/guide/en/#outputassetfilenames
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const content = Buffer.from('text');
|
|
23
|
+
* const fileName = assetFileNamesToFileName(
|
|
24
|
+
* 'assets/[name].[hash][extname]',
|
|
25
|
+
* '/path/to/file.txt',
|
|
26
|
+
* getAssetHash(content),
|
|
27
|
+
* content
|
|
28
|
+
* )
|
|
29
|
+
* // fileName: 'assets/file.982d9e3e.txt'
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
|
|
33
|
+
* @param file filepath of the asset
|
|
34
|
+
* @param contentHash hash of the asset. used for `'[hash]'` placeholder
|
|
35
|
+
* @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
|
|
36
|
+
* @returns output filename
|
|
37
|
+
*/
|
|
38
|
+
export declare function assetFileNamesToFileName(assetFileNames: Exclude<OutputOptions['assetFileNames'], undefined>, file: string, contentHash: string, content: string | Buffer): string;
|
|
15
39
|
export declare function getAssetHash(content: Buffer): string;
|
|
16
40
|
export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): string;
|
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.urlToBuiltUrl = exports.getAssetHash = exports.getAssetFilename = exports.fileToUrl = exports.checkPublicFile = exports.registerAssetToChunk = exports.assetPlugin = exports.chunkToEmittedAssetsMap = exports.assetUrlRE = void 0;
|
|
25
|
+
exports.urlToBuiltUrl = exports.getAssetHash = exports.assetFileNamesToFileName = exports.getAssetFilename = exports.fileToUrl = exports.checkPublicFile = exports.registerAssetToChunk = exports.assetPlugin = exports.chunkToEmittedAssetsMap = exports.assetUrlRE = void 0;
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
27
|
const url_1 = require("url");
|
|
28
28
|
const lite_1 = __importDefault(require("mime/lite"));
|
|
@@ -142,6 +142,66 @@ function getAssetFilename(hash, config) {
|
|
|
142
142
|
return (_a = assetHashToFilenameMap.get(config)) === null || _a === void 0 ? void 0 : _a.get(hash);
|
|
143
143
|
}
|
|
144
144
|
exports.getAssetFilename = getAssetFilename;
|
|
145
|
+
/**
|
|
146
|
+
* converts the source filepath of the asset to the output filename based on the assetFileNames option. \
|
|
147
|
+
* this function imitates the behavior of rollup.js. \
|
|
148
|
+
* https://rollupjs.org/guide/en/#outputassetfilenames
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const content = Buffer.from('text');
|
|
153
|
+
* const fileName = assetFileNamesToFileName(
|
|
154
|
+
* 'assets/[name].[hash][extname]',
|
|
155
|
+
* '/path/to/file.txt',
|
|
156
|
+
* getAssetHash(content),
|
|
157
|
+
* content
|
|
158
|
+
* )
|
|
159
|
+
* // fileName: 'assets/file.982d9e3e.txt'
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
|
|
163
|
+
* @param file filepath of the asset
|
|
164
|
+
* @param contentHash hash of the asset. used for `'[hash]'` placeholder
|
|
165
|
+
* @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
|
|
166
|
+
* @returns output filename
|
|
167
|
+
*/
|
|
168
|
+
function assetFileNamesToFileName(assetFileNames, file, contentHash, content) {
|
|
169
|
+
const basename = path_1.default.basename(file);
|
|
170
|
+
// placeholders for `assetFileNames`
|
|
171
|
+
// `hash` is slightly different from the rollup's one
|
|
172
|
+
const extname = path_1.default.extname(basename);
|
|
173
|
+
const ext = extname.substring(1);
|
|
174
|
+
const name = basename.slice(0, -extname.length);
|
|
175
|
+
const hash = contentHash;
|
|
176
|
+
if (typeof assetFileNames === 'function') {
|
|
177
|
+
assetFileNames = assetFileNames({
|
|
178
|
+
name: file,
|
|
179
|
+
source: content,
|
|
180
|
+
type: 'asset',
|
|
181
|
+
});
|
|
182
|
+
if (typeof assetFileNames !== 'string') {
|
|
183
|
+
throw new TypeError('assetFileNames must return a string');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (typeof assetFileNames !== 'string') {
|
|
187
|
+
throw new TypeError('assetFileNames must be a string or a function');
|
|
188
|
+
}
|
|
189
|
+
const fileName = assetFileNames.replace(/\[\w+\]/g, (placeholder) => {
|
|
190
|
+
switch (placeholder) {
|
|
191
|
+
case '[ext]':
|
|
192
|
+
return ext;
|
|
193
|
+
case '[extname]':
|
|
194
|
+
return extname;
|
|
195
|
+
case '[hash]':
|
|
196
|
+
return hash;
|
|
197
|
+
case '[name]':
|
|
198
|
+
return name;
|
|
199
|
+
}
|
|
200
|
+
throw new Error(`invalid placeholder ${placeholder} in assetFileNames "${assetFileNames}"`);
|
|
201
|
+
});
|
|
202
|
+
return fileName;
|
|
203
|
+
}
|
|
204
|
+
exports.assetFileNamesToFileName = assetFileNamesToFileName;
|
|
145
205
|
/**
|
|
146
206
|
* Register an asset to be emitted as part of the bundle (if necessary)
|
|
147
207
|
* and returns the resolved public URL
|
|
@@ -167,7 +227,10 @@ function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false, canI
|
|
|
167
227
|
const contentHash = getAssetHash(content);
|
|
168
228
|
const { search, hash } = (0, url_1.parse)(id);
|
|
169
229
|
const postfix = (search || '') + (hash || '');
|
|
170
|
-
const
|
|
230
|
+
const inputDir = (0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR);
|
|
231
|
+
let fileName = file.startsWith(inputDir)
|
|
232
|
+
? path_1.default.posix.relative(inputDir, file)
|
|
233
|
+
: assetFileNamesToFileName(path_1.default.posix.join(config.build.assetsDir, '[name].[hash][extname]'), file, contentHash, content);
|
|
171
234
|
if (!map.has(contentHash)) {
|
|
172
235
|
map.set(contentHash, fileName);
|
|
173
236
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "3.0.0-alpha-
|
|
3
|
+
"version": "3.0.0-alpha-3030220211217009",
|
|
4
4
|
"description": "@dcloudio/uni-cli-shared",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/parser": "^7.16.4",
|
|
22
22
|
"@babel/types": "^7.16.0",
|
|
23
|
-
"@dcloudio/uni-i18n": "3.0.0-alpha-
|
|
24
|
-
"@dcloudio/uni-shared": "3.0.0-alpha-
|
|
23
|
+
"@dcloudio/uni-i18n": "3.0.0-alpha-3030220211217009",
|
|
24
|
+
"@dcloudio/uni-shared": "3.0.0-alpha-3030220211217009",
|
|
25
25
|
"@rollup/pluginutils": "^4.1.2",
|
|
26
26
|
"@vue/compiler-core": "3.2.26",
|
|
27
27
|
"@vue/compiler-dom": "3.2.26",
|