Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ node_modules/
package-lock.json

coverage/
.nyc_output
*.log
*.swo
*.swp
90 changes: 55 additions & 35 deletions bin/set-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

'use strict';
import fs from 'fs';
import path from 'path';
import { isBuiltin } from 'node:module';
import { fileURLToPath } from 'url';

const fs = require('fs');
const path = require('path');
const { isBuiltin } = require('node:module');

const findRequires = require('find-requires');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const topPkgDir = path.resolve(__dirname, '..');
const topPkg = JSON.parse(fs.readFileSync(path.join(topPkgDir, 'package.json'), 'utf8'));
Expand All @@ -15,44 +15,64 @@ const definedDependencies = Object.keys(topPkg.dependencies);
const pkgsDir = path.join(topPkgDir, 'packages/node_modules');
const pkgNames = fs.readdirSync(pkgsDir);

/**
* Recursively find all .js files in a directory
*/
function findJsFiles(dir) {
const results = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== 'test' && entry.name !== 'spec') {
results.push(...findJsFiles(fullPath));
} else if (entry.isFile() && entry.name.endsWith('.js')) {
results.push(fullPath);
}
}
return results;
}

/**
* Extract import specifiers from ESM source code using regex.
* Handles: import X from 'pkg', import { X } from 'pkg', import 'pkg'
*/
function findImports(source) {
const imports = [];
// Match static import statements
const importRegex = /import\s+(?:[\s\S]*?\s+from\s+)?['"]([^'"]+)['"]/g;
let match;
while ((match = importRegex.exec(source)) !== null) {
imports.push(match[1]);
}
// Match dynamic imports
const dynamicRegex = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
while ((match = dynamicRegex.exec(source)) !== null) {
imports.push(match[1]);
}
return imports;
}

for (const pkgName of pkgNames) {
const pkgDir = path.join(pkgsDir, pkgName);
const pkgPath = path.join(pkgDir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

const main = pkg.main || 'index.js';
const mainPath = path.join(pkgDir, main);

/**
* Dependency Detection
*
* Caveats:
*
* 1. Assumes library is requirable without side-effects, which it should be
* 2. Doesn't allow for coniditional requires or anything in that realm
* 3. Assumes single entry-point
*
* Benefits:
*
* 1. Doesn't assume location of script files?
*
* A better approach might be to look at "files" in package.json
*/
for (const key of Object.keys(require.cache)) {
delete require.cache[key];
* Dependency Detection
*
* Scans all source .js files for import statements and extracts
* package names from the import specifiers.
*/
const jsFiles = findJsFiles(pkgDir);
const allImports = [];
for (const file of jsFiles) {
const source = fs.readFileSync(file, 'utf8');
allImports.push(...findImports(source));
}
require(mainPath);

const modulesInPackage = Object
.keys(require.cache)
.filter(id => id.startsWith(pkgDir + '/'));
const requiresInPackage = Array.prototype.concat.apply(
[],
modulesInPackage.map(m => findRequires(fs.readFileSync(m, 'utf8')))
);

const packageRequires = Array.from(new Set(
requiresInPackage
allImports
.filter(id => id[0] !== '.' && id[0] !== '/')
.filter(id => !id.startsWith('node:'))
.map(id => {
let slash = id.indexOf('/');
if (slash === -1) {
Expand Down
8 changes: 5 additions & 3 deletions bin/set-meta.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node

'use strict';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const fs = require('fs');
const path = require('path');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const COMMON_META = [
'author',
Expand Down
8 changes: 5 additions & 3 deletions bin/set-version.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node

'use strict';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const fs = require('fs');
const path = require('path');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const version = process.argv[process.argv.length - 1];

Expand Down
36 changes: 17 additions & 19 deletions bin/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,28 @@ source "$(dirname ${BASH_SOURCE[0]})/helpers.sh"

TOP_DIR=$(pwd)

rm -r .nyc_output 2>/dev/null || :
rm -rf coverage 2>/dev/null || :
mkdir -p coverage/tmp

EXIT_CODE=0

for package in $(get_packages); do
cd "${package}"

set +e
npm test
EXIT_CODE+=$?
set -e

cd "${TOP_DIR}"
if [ -d "${package}/.nyc_output" ]; then
./node_modules/.bin/nyc \
merge \
"${package}/.nyc_output" \
".nyc_output/$(basename "${package}").json"
fi
cd "${package}"

set +e
npm test
EXIT_CODE+=$?
set -e

cd "${TOP_DIR}"
if [ -d "${package}/coverage/tmp" ]; then
cp "${package}"/coverage/tmp/*.json coverage/tmp/ 2>/dev/null || :
fi
done

./node_modules/.bin/nyc report \
--exclude-node-modules false \
--reporter text \
--reporter lcov
./node_modules/.bin/c8 report \
--all \
--reporter text \
--reporter lcov

exit $EXIT_CODE
4 changes: 1 addition & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export default defineConfig([
{
languageOptions: {
parserOptions: {
ecmaVersion: 8,
type: 'commonjs',
ecmaVersion: 2022,
}
},
rules: {
Expand All @@ -18,7 +17,6 @@ export default defineConfig([
},
globalIgnores([
'coverage',
'.nyc_output',
'!packages/node_modules/',
]),
], {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
},
"devDependencies": {
"aws-sdk": "^2.179.0",
"chai": "^4.1.1",
"chai-as-promised": "^7.1.1",
"c8": "^11.0.0",
"chai": "^5.2.0",
"chai-as-promised": "^8.0.0",
"dynamodb-local": "0.0.31",
"eslint": "^9.26.0",
"eslint-config-brightspace": "^2.7.2",
"find-requires": "^1.0.0",
"mocha": "^11.1.0",
"nyc": "^17.1.0",
"redis": "^2.8.0",
"sinon": "^20.0.0",
"undici": "^7.8.0"
}
},
"type": "module"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions packages/node_modules/brightspace-auth-assertions/src/errors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading