MCPcopy Create free account
hub / github.com/BridgeAR/safe-stable-stringify / writePackage

Function writePackage

test-modules.js:27–46  ·  view source on GitHub ↗

* @param {string} directory * @param {string} packageVersion

(directory, packageVersion)

Source from the content-addressed store, hash-verified

25 * @param {string} packageVersion
26 */
27function writePackage (directory, packageVersion) {
28 const files = {
29 '': ['package.json', 'index.js', 'index.d.ts', 'wrapper.cjs'],
30 esm: readdirSync(join(__dirname, 'esm'))
31 }
32 for (const [subdirectory, names] of Object.entries(files)) {
33 mkdirSync(join(directory, subdirectory), { recursive: true })
34 for (const name of names) {
35 let source = readFileSync(join(__dirname, subdirectory, name), 'utf8')
36 if (name === 'package.json') {
37 const metadata = JSON.parse(source)
38 metadata.version = packageVersion
39 source = JSON.stringify(metadata)
40 } else {
41 source = source.replaceAll(`safe-stable-stringify@${version}`, `safe-stable-stringify@${packageVersion}`)
42 }
43 writeFileSync(join(directory, subdirectory, name), source)
44 }
45 }
46}
47
48/** @param {import('tap').Test} assert */
49function createPackageFixture (assert) {

Callers 2

createPackageFixtureFunction · 0.85
testModuleEntryPointsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected