@salesforce/core 6.2.3-qa.1 → 6.4.0
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/lib/messages.d.ts +12 -0
- package/lib/messages.js +15 -0
- package/package.json +1 -1
package/lib/messages.d.ts
CHANGED
|
@@ -78,6 +78,9 @@ export type StoredMessageMap = Map<string, StoredMessage>;
|
|
|
78
78
|
* // Create loader functions for all files in the messages directory
|
|
79
79
|
* Messages.importMessagesDirectory(__dirname);
|
|
80
80
|
*
|
|
81
|
+
* // or, for ESM code
|
|
82
|
+
* Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
|
|
83
|
+
*
|
|
81
84
|
* // Now you can use the messages from anywhere in your code or file.
|
|
82
85
|
* // If using importMessageDirectory, the bundle name is the file name.
|
|
83
86
|
* const messages: Messages = Messages.loadMessages(packageName, bundleName);
|
|
@@ -146,6 +149,15 @@ export declare class Messages<T extends string> {
|
|
|
146
149
|
* @param filePath The path of the file.
|
|
147
150
|
*/
|
|
148
151
|
static importMessageFile(packageName: string, filePath: string): void;
|
|
152
|
+
/**
|
|
153
|
+
* Support ESM plugins who can't use __dirname
|
|
154
|
+
*
|
|
155
|
+
* @param metaUrl pass in `import.meta.url`
|
|
156
|
+
* @param truncateToProjectPath Will look for the messages directory in the project root (where the package.json file is located).
|
|
157
|
+
* i.e., the module is typescript and the messages folder is in the top level of the module directory.
|
|
158
|
+
* @param packageName The npm package name. Figured out from the root directory's package.json.
|
|
159
|
+
*/
|
|
160
|
+
static importMessagesDirectoryFromMetaUrl(metaUrl: string, truncateToProjectPath?: boolean, packageName?: string): void;
|
|
149
161
|
/**
|
|
150
162
|
* Import all json and js files in a messages directory. Use the file name as the bundle key when
|
|
151
163
|
* {@link Messages.loadMessages} is called. By default, we're assuming the moduleDirectoryPart is a
|
package/lib/messages.js
CHANGED
|
@@ -11,6 +11,7 @@ const fs = require("node:fs");
|
|
|
11
11
|
const os = require("node:os");
|
|
12
12
|
const path = require("node:path");
|
|
13
13
|
const util = require("node:util");
|
|
14
|
+
const node_url_1 = require("node:url");
|
|
14
15
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
16
|
const kit_1 = require("@salesforce/kit");
|
|
16
17
|
const sfError_1 = require("./sfError");
|
|
@@ -138,6 +139,9 @@ const jsAndJsonLoader = (filePath, fileContents) => {
|
|
|
138
139
|
* // Create loader functions for all files in the messages directory
|
|
139
140
|
* Messages.importMessagesDirectory(__dirname);
|
|
140
141
|
*
|
|
142
|
+
* // or, for ESM code
|
|
143
|
+
* Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
|
|
144
|
+
*
|
|
141
145
|
* // Now you can use the messages from anywhere in your code or file.
|
|
142
146
|
* // If using importMessageDirectory, the bundle name is the file name.
|
|
143
147
|
* const messages: Messages = Messages.loadMessages(packageName, bundleName);
|
|
@@ -229,6 +233,17 @@ class Messages {
|
|
|
229
233
|
this.setLoaderFunction(packageName, bundleName, Messages.generateFileLoaderFunction(bundleName, filePath));
|
|
230
234
|
}
|
|
231
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Support ESM plugins who can't use __dirname
|
|
238
|
+
*
|
|
239
|
+
* @param metaUrl pass in `import.meta.url`
|
|
240
|
+
* @param truncateToProjectPath Will look for the messages directory in the project root (where the package.json file is located).
|
|
241
|
+
* i.e., the module is typescript and the messages folder is in the top level of the module directory.
|
|
242
|
+
* @param packageName The npm package name. Figured out from the root directory's package.json.
|
|
243
|
+
*/
|
|
244
|
+
static importMessagesDirectoryFromMetaUrl(metaUrl, truncateToProjectPath = true, packageName) {
|
|
245
|
+
return Messages.importMessagesDirectory(path.dirname((0, node_url_1.fileURLToPath)(metaUrl)), truncateToProjectPath, packageName);
|
|
246
|
+
}
|
|
232
247
|
/**
|
|
233
248
|
* Import all json and js files in a messages directory. Use the file name as the bundle key when
|
|
234
249
|
* {@link Messages.loadMessages} is called. By default, we're assuming the moduleDirectoryPart is a
|