@codama/renderers-js 1.5.3 → 1.5.5
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/index.browser.cjs +19 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +19 -19
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.cjs +20 -18
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +21 -20
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.react-native.mjs +19 -19
- package/dist/index.react-native.mjs.map +1 -1
- package/dist/types/utils/formatCode.d.ts +4 -4
- package/dist/types/utils/formatCode.d.ts.map +1 -1
- package/dist/types/utils/packageJson.d.ts +3 -2
- package/dist/types/utils/packageJson.d.ts.map +1 -1
- package/dist/types/visitors/renderVisitor.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.node.cjs
CHANGED
|
@@ -7,8 +7,10 @@ var renderersCore = require('@codama/renderers-core');
|
|
|
7
7
|
var visitorsCore = require('@codama/visitors-core');
|
|
8
8
|
var codecsStrings = require('@solana/codecs-strings');
|
|
9
9
|
var prettier = require('prettier');
|
|
10
|
+
var babelPlugin = require('prettier/plugins/babel');
|
|
10
11
|
var estreePlugin = require('prettier/plugins/estree');
|
|
11
12
|
var typeScriptPlugin = require('prettier/plugins/typescript');
|
|
13
|
+
var standalone = require('prettier/standalone');
|
|
12
14
|
var errors = require('@codama/errors');
|
|
13
15
|
var semver = require('semver');
|
|
14
16
|
|
|
@@ -30,6 +32,7 @@ function _interopNamespace(e) {
|
|
|
30
32
|
return Object.freeze(n);
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
var babelPlugin__namespace = /*#__PURE__*/_interopNamespace(babelPlugin);
|
|
33
36
|
var estreePlugin__namespace = /*#__PURE__*/_interopNamespace(estreePlugin);
|
|
34
37
|
var typeScriptPlugin__namespace = /*#__PURE__*/_interopNamespace(typeScriptPlugin);
|
|
35
38
|
|
|
@@ -409,29 +412,22 @@ var getDefinedTypeNodesToExtract = (nodes$1, parsedCustomDataOptions) => nodes$1
|
|
|
409
412
|
];
|
|
410
413
|
});
|
|
411
414
|
var DEFAULT_PRETTIER_OPTIONS = {
|
|
412
|
-
|
|
413
|
-
parser: "typescript",
|
|
414
|
-
plugins: [estreePlugin__namespace, typeScriptPlugin__namespace],
|
|
415
|
-
printWidth: 80,
|
|
416
|
-
semi: true,
|
|
417
|
-
singleQuote: true,
|
|
418
|
-
tabWidth: 2,
|
|
419
|
-
trailingComma: "es5",
|
|
420
|
-
useTabs: false
|
|
415
|
+
plugins: [estreePlugin__namespace, typeScriptPlugin__namespace, babelPlugin__namespace]
|
|
421
416
|
};
|
|
422
|
-
async function
|
|
417
|
+
async function getCodeFormatter(options) {
|
|
423
418
|
const shouldFormatCode = options.formatCode ?? true;
|
|
424
|
-
if (!shouldFormatCode) return
|
|
419
|
+
if (!shouldFormatCode) return (code) => Promise.resolve(code);
|
|
425
420
|
const prettierOptions = {
|
|
426
421
|
...DEFAULT_PRETTIER_OPTIONS,
|
|
427
422
|
...await resolvePrettierOptions(options.packageFolder),
|
|
428
423
|
...options.prettierOptions
|
|
429
424
|
};
|
|
430
|
-
return
|
|
425
|
+
return (code, filepath) => standalone.format(code, { ...prettierOptions, filepath });
|
|
431
426
|
}
|
|
432
427
|
async function resolvePrettierOptions(packageFolder) {
|
|
433
428
|
if (!packageFolder) return null;
|
|
434
|
-
|
|
429
|
+
const filePathToResolve = renderersCore.joinPath(packageFolder, "package.json");
|
|
430
|
+
return await prettier.resolveConfig(filePathToResolve);
|
|
435
431
|
}
|
|
436
432
|
function getImportFromFactory(overrides, customAccountData, customInstructionData) {
|
|
437
433
|
const customDataOverrides = Object.fromEntries(
|
|
@@ -490,7 +486,7 @@ var DEFAULT_DEPENDENCY_VERSIONS = {
|
|
|
490
486
|
"@solana/rpc-types": "^5.0.0",
|
|
491
487
|
"@solana/signers": "^5.0.0"
|
|
492
488
|
};
|
|
493
|
-
function syncPackageJson(renderMap, options) {
|
|
489
|
+
async function syncPackageJson(renderMap, formatCode, options) {
|
|
494
490
|
const shouldSyncPackageJson = options.syncPackageJson ?? false;
|
|
495
491
|
const packageFolder = options.packageFolder;
|
|
496
492
|
if (!packageFolder) {
|
|
@@ -514,10 +510,10 @@ function syncPackageJson(renderMap, options) {
|
|
|
514
510
|
}
|
|
515
511
|
if (renderersCore.fileExists(packageJsonPath)) {
|
|
516
512
|
const packageJson = updateExistingPackageJson(renderersCore.readJson(packageJsonPath), usedDependencies);
|
|
517
|
-
|
|
513
|
+
await writePackageJson(packageJson, packageJsonPath, formatCode);
|
|
518
514
|
} else {
|
|
519
515
|
const packageJson = createNewPackageJson(usedDependencies);
|
|
520
|
-
|
|
516
|
+
await writePackageJson(packageJson, packageJsonPath, formatCode);
|
|
521
517
|
}
|
|
522
518
|
}
|
|
523
519
|
function createNewPackageJson(dependencyVersions) {
|
|
@@ -645,6 +641,11 @@ function updateDependency(dependencyGroup, dependency, requiredRange) {
|
|
|
645
641
|
if (!shouldUpdateRange(dependency, currentRange, requiredRange)) return;
|
|
646
642
|
dependencyGroup[dependency] = requiredRange;
|
|
647
643
|
}
|
|
644
|
+
async function writePackageJson(packageJson, packageJsonPath, formatCode) {
|
|
645
|
+
const packageJsonContent = JSON.stringify(packageJson, null, 2) + "\n";
|
|
646
|
+
const formattedContent = await formatCode(packageJsonContent, packageJsonPath);
|
|
647
|
+
renderersCore.writeFile(packageJsonPath, formattedContent);
|
|
648
|
+
}
|
|
648
649
|
|
|
649
650
|
// src/fragments/accountFetchHelpers.ts
|
|
650
651
|
function getAccountFetchHelpersFragment(scope) {
|
|
@@ -3226,8 +3227,9 @@ function renderVisitor(path, options = {}) {
|
|
|
3226
3227
|
renderersCore.deleteDirectory(path);
|
|
3227
3228
|
}
|
|
3228
3229
|
let renderMap = visitorsCore.visit(root, getRenderMapVisitor(options));
|
|
3229
|
-
|
|
3230
|
-
|
|
3230
|
+
const formatCode = await getCodeFormatter(options);
|
|
3231
|
+
renderMap = await renderersCore.mapRenderMapContentAsync(renderMap, formatCode);
|
|
3232
|
+
await syncPackageJson(renderMap, formatCode, options);
|
|
3231
3233
|
renderersCore.writeRenderMap(renderMap, path);
|
|
3232
3234
|
});
|
|
3233
3235
|
}
|