Commit 9f15fd4
Changed files (10)
scripts/build-tests.mjs
@@ -0,0 +1,51 @@
+#!/usr/bin/env node
+
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import fs from 'node:fs'
+import path from 'node:path'
+import * as vendor from '../build/vendor.js'
+
+const __dirname = path.dirname(new URL(import.meta.url).pathname)
+const root = path.resolve(__dirname, '..')
+const apis = ['chalk', 'depseek', 'fs', 'minimist', 'ps', 'which', 'YAML']
+
+const copyright = await fs.readFileSync(
+ path.resolve(root, 'test/fixtures/copyright.txt'),
+ 'utf8'
+)
+
+// prettier-ignore
+apis.forEach((name) => {
+ const api = vendor[name]
+ const methods = Object.entries(api)
+ const formatAssert = (k, v, prefix = ' ') => `${prefix}assert.equal(typeof ${name}.${k}, '${typeof v}')`
+ const methodChecks = methods.length
+ ? '\n' + methods.map(([k, v]) => formatAssert(k, v)).join('\n')
+ : ''
+ const filePath = path.resolve(root, `test/vendor-${name.toLowerCase()}.test.js`)
+ const fileContents = `${copyright.replace('YEAR', new Date().getFullYear())}
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { ${name} } from '../build/vendor.js'
+
+describe('vendor ${name} API ', () => {
+ test('exports', () => {
+ assert.equal(typeof ${name}, '${typeof api}')${methodChecks}
+ })
+})
+`
+ fs.writeFileSync(filePath, fileContents)
+})
scripts/generate-vendor-tests.mjs
@@ -1,89 +0,0 @@
-#!/usr/bin/env node
-
-// Copyright 2024 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-import fs from 'node:fs'
-import path from 'node:path'
-import process from 'node:process'
-
-import { YAML, fs as vendorFs } from '../build/vendor.js'
-
-const copyright = `// Copyright 2024 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.`
-
-const testLibImports = `import assert from 'node:assert'
-import { test, describe } from 'node:test'`
-
-const newLine = '\n'
-
-const vendors = [
- {
- name: 'YAML',
- module: YAML,
- },
- {
- name: 'fs',
- module: vendorFs,
- },
-]
-
-const cwd = process.cwd()
-
-vendors.forEach(({ name, module }) => {
- const outputFile = path.resolve(
- cwd,
- `test/vendor-${name.toLowerCase()}.test.js`
- )
-
- const moduleImport = `import { ${name} } from '../build/vendor.js'`
-
- const fileText = [
- copyright,
- newLine,
- testLibImports,
- moduleImport,
- newLine,
- createDescribeBlock(
- name,
- createTestBlock(
- 'has proper exports',
- Object.entries(module)
- .map(([k, v]) => `assert.equal(typeof ${name}.${k}, '${typeof v}')`)
- .join('\n')
- )
- ),
- ].join('\n')
-
- fs.writeFileSync(outputFile, fileText)
-})
-
-function createDescribeBlock(vendorName, content) {
- return [`describe('vendor ${vendorName}', () => {`, content, '})'].join('\n')
-}
-
-function createTestBlock(label, content) {
- return [`test('${label}', () => {`, content, '})'].join('\n')
-}
test/vendor-chalk.test.js
@@ -0,0 +1,24 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { chalk } from '../build/vendor.js'
+
+describe('vendor chalk API ', () => {
+ test('exports', () => {
+ assert.equal(typeof chalk, 'function')
+ assert.equal(typeof chalk.level, 'number')
+ })
+})
test/vendor-depseek.test.js
@@ -0,0 +1,23 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { depseek } from '../build/vendor.js'
+
+describe('vendor depseek API ', () => {
+ test('exports', () => {
+ assert.equal(typeof depseek, 'function')
+ })
+})
test/vendor-fs.test.js
@@ -0,0 +1,175 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { fs } from '../build/vendor.js'
+
+describe('vendor fs API ', () => {
+ test('exports', () => {
+ assert.equal(typeof fs, 'object')
+ assert.equal(typeof fs.default, 'object')
+ assert.equal(typeof fs.appendFile, 'function')
+ assert.equal(typeof fs.appendFileSync, 'function')
+ assert.equal(typeof fs.access, 'function')
+ assert.equal(typeof fs.accessSync, 'function')
+ assert.equal(typeof fs.chown, 'function')
+ assert.equal(typeof fs.chownSync, 'function')
+ assert.equal(typeof fs.chmod, 'function')
+ assert.equal(typeof fs.chmodSync, 'function')
+ assert.equal(typeof fs.close, 'function')
+ assert.equal(typeof fs.closeSync, 'function')
+ assert.equal(typeof fs.copyFile, 'function')
+ assert.equal(typeof fs.copyFileSync, 'function')
+ assert.equal(typeof fs.cp, 'function')
+ assert.equal(typeof fs.cpSync, 'function')
+ assert.equal(typeof fs.createReadStream, 'function')
+ assert.equal(typeof fs.createWriteStream, 'function')
+ assert.equal(typeof fs.exists, 'function')
+ assert.equal(typeof fs.existsSync, 'function')
+ assert.equal(typeof fs.fchown, 'function')
+ assert.equal(typeof fs.fchownSync, 'function')
+ assert.equal(typeof fs.fchmod, 'function')
+ assert.equal(typeof fs.fchmodSync, 'function')
+ assert.equal(typeof fs.fdatasync, 'function')
+ assert.equal(typeof fs.fdatasyncSync, 'function')
+ assert.equal(typeof fs.fstat, 'function')
+ assert.equal(typeof fs.fstatSync, 'function')
+ assert.equal(typeof fs.fsync, 'function')
+ assert.equal(typeof fs.fsyncSync, 'function')
+ assert.equal(typeof fs.ftruncate, 'function')
+ assert.equal(typeof fs.ftruncateSync, 'function')
+ assert.equal(typeof fs.futimes, 'function')
+ assert.equal(typeof fs.futimesSync, 'function')
+ assert.equal(typeof fs.glob, 'function')
+ assert.equal(typeof fs.globSync, 'function')
+ assert.equal(typeof fs.lchown, 'function')
+ assert.equal(typeof fs.lchownSync, 'function')
+ assert.equal(typeof fs.lchmod, 'function')
+ assert.equal(typeof fs.lchmodSync, 'function')
+ assert.equal(typeof fs.link, 'function')
+ assert.equal(typeof fs.linkSync, 'function')
+ assert.equal(typeof fs.lstat, 'function')
+ assert.equal(typeof fs.lstatSync, 'function')
+ assert.equal(typeof fs.lutimes, 'function')
+ assert.equal(typeof fs.lutimesSync, 'function')
+ assert.equal(typeof fs.mkdir, 'function')
+ assert.equal(typeof fs.mkdirSync, 'function')
+ assert.equal(typeof fs.mkdtemp, 'function')
+ assert.equal(typeof fs.mkdtempSync, 'function')
+ assert.equal(typeof fs.open, 'function')
+ assert.equal(typeof fs.openSync, 'function')
+ assert.equal(typeof fs.openAsBlob, 'function')
+ assert.equal(typeof fs.readdir, 'function')
+ assert.equal(typeof fs.readdirSync, 'function')
+ assert.equal(typeof fs.read, 'function')
+ assert.equal(typeof fs.readSync, 'function')
+ assert.equal(typeof fs.readv, 'function')
+ assert.equal(typeof fs.readvSync, 'function')
+ assert.equal(typeof fs.readFile, 'function')
+ assert.equal(typeof fs.readFileSync, 'function')
+ assert.equal(typeof fs.readlink, 'function')
+ assert.equal(typeof fs.readlinkSync, 'function')
+ assert.equal(typeof fs.realpath, 'function')
+ assert.equal(typeof fs.realpathSync, 'function')
+ assert.equal(typeof fs.rename, 'function')
+ assert.equal(typeof fs.renameSync, 'function')
+ assert.equal(typeof fs.rm, 'function')
+ assert.equal(typeof fs.rmSync, 'function')
+ assert.equal(typeof fs.rmdir, 'function')
+ assert.equal(typeof fs.rmdirSync, 'function')
+ assert.equal(typeof fs.stat, 'function')
+ assert.equal(typeof fs.statfs, 'function')
+ assert.equal(typeof fs.statSync, 'function')
+ assert.equal(typeof fs.statfsSync, 'function')
+ assert.equal(typeof fs.symlink, 'function')
+ assert.equal(typeof fs.symlinkSync, 'function')
+ assert.equal(typeof fs.truncate, 'function')
+ assert.equal(typeof fs.truncateSync, 'function')
+ assert.equal(typeof fs.unwatchFile, 'function')
+ assert.equal(typeof fs.unlink, 'function')
+ assert.equal(typeof fs.unlinkSync, 'function')
+ assert.equal(typeof fs.utimes, 'function')
+ assert.equal(typeof fs.utimesSync, 'function')
+ assert.equal(typeof fs.watch, 'function')
+ assert.equal(typeof fs.watchFile, 'function')
+ assert.equal(typeof fs.writeFile, 'function')
+ assert.equal(typeof fs.writeFileSync, 'function')
+ assert.equal(typeof fs.write, 'function')
+ assert.equal(typeof fs.writeSync, 'function')
+ assert.equal(typeof fs.writev, 'function')
+ assert.equal(typeof fs.writevSync, 'function')
+ assert.equal(typeof fs.Dirent, 'function')
+ assert.equal(typeof fs.Stats, 'function')
+ assert.equal(typeof fs.ReadStream, 'function')
+ assert.equal(typeof fs.WriteStream, 'function')
+ assert.equal(typeof fs.FileReadStream, 'function')
+ assert.equal(typeof fs.FileWriteStream, 'function')
+ assert.equal(typeof fs._toUnixTimestamp, 'function')
+ assert.equal(typeof fs.Dir, 'function')
+ assert.equal(typeof fs.opendir, 'function')
+ assert.equal(typeof fs.opendirSync, 'function')
+ assert.equal(typeof fs.F_OK, 'number')
+ assert.equal(typeof fs.R_OK, 'number')
+ assert.equal(typeof fs.W_OK, 'number')
+ assert.equal(typeof fs.X_OK, 'number')
+ assert.equal(typeof fs.constants, 'object')
+ assert.equal(typeof fs.promises, 'object')
+ assert.equal(typeof fs.gracefulify, 'function')
+ assert.equal(typeof fs.copy, 'function')
+ assert.equal(typeof fs.copySync, 'function')
+ assert.equal(typeof fs.emptyDirSync, 'function')
+ assert.equal(typeof fs.emptydirSync, 'function')
+ assert.equal(typeof fs.emptyDir, 'function')
+ assert.equal(typeof fs.emptydir, 'function')
+ assert.equal(typeof fs.createFile, 'function')
+ assert.equal(typeof fs.createFileSync, 'function')
+ assert.equal(typeof fs.ensureFile, 'function')
+ assert.equal(typeof fs.ensureFileSync, 'function')
+ assert.equal(typeof fs.createLink, 'function')
+ assert.equal(typeof fs.createLinkSync, 'function')
+ assert.equal(typeof fs.ensureLink, 'function')
+ assert.equal(typeof fs.ensureLinkSync, 'function')
+ assert.equal(typeof fs.createSymlink, 'function')
+ assert.equal(typeof fs.createSymlinkSync, 'function')
+ assert.equal(typeof fs.ensureSymlink, 'function')
+ assert.equal(typeof fs.ensureSymlinkSync, 'function')
+ assert.equal(typeof fs.readJson, 'function')
+ assert.equal(typeof fs.readJsonSync, 'function')
+ assert.equal(typeof fs.writeJson, 'function')
+ assert.equal(typeof fs.writeJsonSync, 'function')
+ assert.equal(typeof fs.outputJson, 'function')
+ assert.equal(typeof fs.outputJsonSync, 'function')
+ assert.equal(typeof fs.outputJSON, 'function')
+ assert.equal(typeof fs.outputJSONSync, 'function')
+ assert.equal(typeof fs.writeJSON, 'function')
+ assert.equal(typeof fs.writeJSONSync, 'function')
+ assert.equal(typeof fs.readJSON, 'function')
+ assert.equal(typeof fs.readJSONSync, 'function')
+ assert.equal(typeof fs.mkdirs, 'function')
+ assert.equal(typeof fs.mkdirsSync, 'function')
+ assert.equal(typeof fs.mkdirp, 'function')
+ assert.equal(typeof fs.mkdirpSync, 'function')
+ assert.equal(typeof fs.ensureDir, 'function')
+ assert.equal(typeof fs.ensureDirSync, 'function')
+ assert.equal(typeof fs.move, 'function')
+ assert.equal(typeof fs.moveSync, 'function')
+ assert.equal(typeof fs.outputFile, 'function')
+ assert.equal(typeof fs.outputFileSync, 'function')
+ assert.equal(typeof fs.pathExists, 'function')
+ assert.equal(typeof fs.pathExistsSync, 'function')
+ assert.equal(typeof fs.remove, 'function')
+ assert.equal(typeof fs.removeSync, 'function')
+ })
+})
test/vendor-minimist.test.js
@@ -0,0 +1,23 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { minimist } from '../build/vendor.js'
+
+describe('vendor minimist API ', () => {
+ test('exports', () => {
+ assert.equal(typeof minimist, 'function')
+ })
+})
test/vendor-ps.test.js
@@ -0,0 +1,28 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { ps } from '../build/vendor.js'
+
+describe('vendor ps API ', () => {
+ test('exports', () => {
+ assert.equal(typeof ps, 'object')
+ assert.equal(typeof ps.kill, 'function')
+ assert.equal(typeof ps.lookup, 'function')
+ assert.equal(typeof ps.lookupSync, 'function')
+ assert.equal(typeof ps.tree, 'function')
+ assert.equal(typeof ps.treeSync, 'function')
+ })
+})
test/vendor-which.test.js
@@ -0,0 +1,24 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { which } from '../build/vendor.js'
+
+describe('vendor which API ', () => {
+ test('exports', () => {
+ assert.equal(typeof which, 'function')
+ assert.equal(typeof which.sync, 'function')
+ })
+})
test/vendor-yaml.test.js
@@ -0,0 +1,53 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import assert from 'node:assert'
+import { test, describe } from 'node:test'
+import { YAML } from '../build/vendor.js'
+
+describe('vendor YAML API ', () => {
+ test('exports', () => {
+ assert.equal(typeof YAML, 'object')
+ assert.equal(typeof YAML.Alias, 'function')
+ assert.equal(typeof YAML.CST, 'object')
+ assert.equal(typeof YAML.Composer, 'function')
+ assert.equal(typeof YAML.Document, 'function')
+ assert.equal(typeof YAML.Lexer, 'function')
+ assert.equal(typeof YAML.LineCounter, 'function')
+ assert.equal(typeof YAML.Pair, 'function')
+ assert.equal(typeof YAML.Parser, 'function')
+ assert.equal(typeof YAML.Scalar, 'function')
+ assert.equal(typeof YAML.Schema, 'function')
+ assert.equal(typeof YAML.YAMLError, 'function')
+ assert.equal(typeof YAML.YAMLMap, 'function')
+ assert.equal(typeof YAML.YAMLParseError, 'function')
+ assert.equal(typeof YAML.YAMLSeq, 'function')
+ assert.equal(typeof YAML.YAMLWarning, 'function')
+ assert.equal(typeof YAML.default, 'object')
+ assert.equal(typeof YAML.isAlias, 'function')
+ assert.equal(typeof YAML.isCollection, 'function')
+ assert.equal(typeof YAML.isDocument, 'function')
+ assert.equal(typeof YAML.isMap, 'function')
+ assert.equal(typeof YAML.isNode, 'function')
+ assert.equal(typeof YAML.isPair, 'function')
+ assert.equal(typeof YAML.isScalar, 'function')
+ assert.equal(typeof YAML.isSeq, 'function')
+ assert.equal(typeof YAML.parse, 'function')
+ assert.equal(typeof YAML.parseAllDocuments, 'function')
+ assert.equal(typeof YAML.parseDocument, 'function')
+ assert.equal(typeof YAML.stringify, 'function')
+ assert.equal(typeof YAML.visit, 'function')
+ assert.equal(typeof YAML.visitAsync, 'function')
+ })
+})
package.json
@@ -62,9 +62,10 @@
"scripts": {
"fmt": "prettier --write .",
"fmt:check": "prettier --check .",
- "build": "npm run build:js && npm run build:dts",
+ "build": "npm run build:js && npm run build:dts && npm run build:tests",
"build:js": "node scripts/build-js.mjs --format=cjs --hybrid --entry=src/*.ts && npm run build:vendor",
"build:vendor": "node scripts/build-js.mjs --format=cjs --entry=src/vendor-*.ts --bundle=all",
+ "build:tests": "node scripts/build-tests.mjs",
"build:dts": "tsc --project tsconfig.prod.json && node scripts/build-dts.mjs",
"pretest": "npm run build",
"test": "npm run test:size && npm run fmt:check && npm run test:unit && npm run test:types && npm run test:license",