Skip to content

Commit

Permalink
Implement inline mod (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni authored Jan 21, 2024
1 parent d789ba3 commit c7a6583
Show file tree
Hide file tree
Showing 38 changed files with 4,616 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-numbers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inox-tools/inline-mod": patch
---

Initial test release
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
packages/**/*.min.js
packages/**/dist/**/*
examples/**/*
/turbo/
.github
.changeset
8 changes: 7 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ automation:

workspace:
# Any config file at the root
- '*.{js,json}'
- '*.{js,json}'
- '.*'

pkg/inline-mod:
- 'packages/inline-mod/**'

pkg/velox-luna:
- 'packages/velox-luna/**'
53 changes: 53 additions & 0 deletions .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Surface PR Changesets

on: pull_request

permissions:
pull-requests: write
checks: write
statuses: write

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get changed files in the .changeset folder
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
.changeset/**/*.md
- name: Check if any changesets contain minor or major changes
id: check
run: |
echo "Checking for changesets marked as minor or major"
echo "found=false" >> $GITHUB_OUTPUT
regex="[\"']astro[\"']: (minor|major)"
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $(cat $file) =~ $regex ]]; then
version="${BASH_REMATCH[1]}"
echo "version=$version" >> $GITHUB_OUTPUT
echo "found=true" >> $GITHUB_OUTPUT
echo "$file has a $version release tag"
fi
done
- name: Add label
uses: actions/github-script@v6
if: steps.check.outputs.found == 'true'
env:
issue_number: ${{ github.event.number }}
with:
script: |
github.rest.issues.addLabels({
issue_number: process.env.issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['semver: ${{ steps.check.outputs.version }}']
});
7 changes: 6 additions & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
name: Label PRs

on:
- pull_request_target
- pull_request

jobs:
triage:
runs-on: ubuntu-latest
permissions:
contents: read
statuses: write
issues: write
pull-requests: write
steps:
- uses: actions/labeler@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
**/fixtures
**/vendor
**/.vercel
/turbo/

# Directories
.github
Expand Down
6 changes: 6 additions & 0 deletions packages/inline-mod/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
rules: {
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-namespace': 'off',
},
};
1 change: 1 addition & 0 deletions packages/inline-mod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Inox-tools Inline Module
3 changes: 3 additions & 0 deletions packages/inline-mod/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
lib
3 changes: 3 additions & 0 deletions packages/inline-mod/npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
src
46 changes: 46 additions & 0 deletions packages/inline-mod/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@inox-tools/inline-mod",
"version": "0.0.0",
"description": "Define a virtual module inline with any reference to buildtime values",
"keywords": [
"vite-plugin"
],
"repository": "https://github.com/Fryuni/inox-tools.git",
"license": "MIT",
"author": "Luiz Ferraz <[email protected]>",
"type": "module",
"exports": {
"./vite": {
"types": "./dist/vite.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"README.md",
"dist"
],
"scripts": {
"build": "tsup",
"clean": "rimraf ./dist",
"test": "vitest",
"dev": "vite --host",
"prepublish": "npm run clean && npm run build"
},
"dependencies": {
"typescript": "^5"
},
"devDependencies": {
"@vitest/ui": "^1.1.3",
"tsup": "^8.0.1",
"upath": "^2.0.1",
"vitest": "^1.1.3"
},
"peerDependencies": {
"vite": "^3.2.0"
},
"peerDependenciesMeta": {
"vite": {
"optional": true
}
}
}
56 changes: 56 additions & 0 deletions packages/inline-mod/src/closure/entry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, expect, it } from 'vitest';
import type { Entry } from './entry.js';
import { EntryRegistry } from './entry.js';

describe('A smart entry registry', () => {
const entry: Entry = {
type: 'expr',
value: 'fooExpr',
};

it('should return the entry added for a key', () => {
const registry = new EntryRegistry();

registry.add('foo', entry);

expect(registry.lookup('foo')).toBe(entry);
expect(registry.lookup('bar')).toBeUndefined();
});

it('should support sealing', () => {
const registry: EntryRegistry<string> = new EntryRegistry<string>();

registry.seal();

expect(() => registry.add('foo', entry)).toThrow();
});

it('should fork into independent copies', () => {
const baseRegistry = new EntryRegistry<string>();

const entryOne: Entry = { type: 'expr', value: 'one' };
const entryTwo: Entry = { type: 'expr', value: 'two' };

baseRegistry.add('foo', entryOne);

const forkOne = baseRegistry.fork();
const forkTwo = forkOne.fork();

expect(forkOne.lookup('foo')).toBe(entryOne);
expect(forkTwo.lookup('foo')).toBe(entryOne);

forkOne.remove('foo');
forkOne.add('foo', entryTwo);

expect(forkTwo.remove('foo')).toBe(entryOne);

expect(baseRegistry.lookup('foo')).toBe(entryOne);
expect(forkOne.lookup('foo')).toBe(entryTwo);
expect(forkTwo.lookup('foo')).toBeUndefined();

baseRegistry.add('bar', entryTwo);

expect(forkOne.lookup('bar')).toBeUndefined();
expect(forkTwo.lookup('bar')).toBeUndefined();
});
});
Loading

0 comments on commit c7a6583

Please sign in to comment.