Skip to content

Commit

Permalink
Merge pull request #1622 from glimmerjs/meta-compile
Browse files Browse the repository at this point in the history
Add CI step for verifying that unwanted code does not get published
  • Loading branch information
NullVoxPopuli authored Sep 13, 2024
2 parents b1aa902 + ddeeb50 commit 489e1fa
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 44 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
node-version: 20.1.0
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: pnpm turbo build
- run: node ./bin/build-verify.mjs

lint:
name: Linting
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
# This creates an .npmrc that reads the NODE_AUTH_TOKEN environment variable
node-registry-url: 'https://registry.npmjs.org'

- run: pnpm turbo build
- run: pnpm turbo build --force --no-cache
- name: npm publish
run: pnpm release-plan publish
env:
Expand Down
55 changes: 55 additions & 0 deletions bin/build-verify.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { globby } from 'globby';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { resolve } from 'node:path';

const currentDir = fileURLToPath(import.meta.url);
const FORBIDDEN = [
/**
* import.meta.env is not a platform standard
*/
'import.meta.env',
/**
* These variables are wrapped around code for this repo only
*/
'VM_LOCAL',
/**
* These are for local VM debugging and development, and are not meant to make it to real code
*/
'check(',
'CheckInterface',
'CheckOr',
'CheckFunction',
'CheckObject',
];

const IGNORED_DIRS = [`@glimmer/syntax`, `@glimmer/debug`];

let files = await globby(resolve(currentDir, '../../packages/**/dist/**/index.js'), {
ignore: ['node_modules', '**/node_modules'],
});

files = files.filter((file) => !IGNORED_DIRS.some((dir) => file.includes(dir)));

let errors = [];

console.log(`Found ${files.length} files to check...`);

for (let filePath of files) {
console.log(`Checking ${filePath}...`);
let file = await readFile(filePath);
let content = file.toString();

for (let searchFor of FORBIDDEN) {
if (content.includes(searchFor)) {
errors.push({ filePath, found: searchFor });
}
}
}

if (errors.length > 0) {
console.error(errors);
throw new Error(`The forbidden texts were encountered in the above files`);
}

console.info('No forbidden texts!');
1 change: 1 addition & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"chalk": "^5.2.0",
"execa": "^7.1.1",
"glob": "^10.2.3",
"globby": "^14.0.2",
"js-yaml": "^4.1.0",
"mkdirp": "^3.0.1",
"puppeteer-chromium-resolver": "^20.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export class Package {
replace({
preventAssignment: true,
values: {
'import.meta.env.MODE': '"development"',
'import.meta.env.DEV': 'DEBUG',
'import.meta.env.PROD': '!DEBUG',
'import.meta.env.VM_LOCAL_DEV': 'false',
Expand Down
Loading

0 comments on commit 489e1fa

Please sign in to comment.