Skip to content

Commit

Permalink
support customization
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Jun 15, 2023
1 parent 7957c82 commit 760f9a6
Show file tree
Hide file tree
Showing 10 changed files with 1,221 additions and 1,104 deletions.
97 changes: 16 additions & 81 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,85 +48,20 @@ jobs:
uses: coactions/setup-xvfb@v1
with:
run: yarn test

# The Windows runner can be super flaky both with Yarn installs and
# when launching browser tests, so we allow for retries in those steps.
test-windows:
name: Test Windows
runs-on: windows-2022
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 14
- name: Install Dependencies
uses: nick-fields/retry@v2
with:
max_attempts: 2
timeout_minutes: 10
command: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Test @glint/core
uses: nick-fields/retry@v2
with:
max_attempts: 2
timeout_minutes: 20
command: yarn workspace @glint/core test
- name: Test glint-vscode
uses: nick-fields/retry@v2
with:
max_attempts: 2
timeout_minutes: 10
command: yarn workspace glint-vscode test
- name: Test @glint/scripts
run: yarn workspace @glint/scripts test

test-floating-deps:
name: Test Floating Dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 14
- name: Install Dependencies
run: yarn install --no-lockfile
- name: Build
run: yarn build
- name: Run Tests
uses: coactions/setup-xvfb@v1
with:
run: yarn test

test-ts-nightly:
name: Test TypeScript Nightly
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
- name: pack
run: cd packages/core && yarn pack
- name: version
id: version
run: echo "version=$(cd packages/core && cat package.json | jq -r '.version')" >> "$GITHUB_OUTPUT"
- name: release
uses: softprops/action-gh-release@v1
id: create_release
with:
node-version: 14
- name: Locate Yarn Cache
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
run: yarn add --dev -W typescript@next
- name: Build
run: yarn build
- name: Run Tests
uses: coactions/setup-xvfb@v1
with:
run: yarn test
fail_on_unmatched_files: true
name: v${{ steps.version.outputs.version }}
tag_name: v${{ steps.version.outputs.version }}
body_path: CHANGELOG.md
files: |
packages/core/glint-core-v${{ steps.version.outputs.version }}.tgz
env:
GITHUB_TOKEN: ${{ github.token }}
66 changes: 66 additions & 0 deletions .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Rebase

# These trigger patterns courtesy of https://github.com/broccolijs/broccoli/pull/436
on:
push:
# filtering branches here prevents duplicate builds from pull_request and push
branches:
- main

# early issue detection: run CI weekly on Sundays
schedule:
- cron: '0 0 * * *'

env:
CI: true

jobs:
rebase:
name: Rebase
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
token: ${{ github.token }}
- name: rebase on original
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git fetch --unshallow
git remote add orig https://github.com/typed-ember/glint.git
git fetch --all
git pull orig main --rebase
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 14
- name: Locate Yarn Cache
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: Run Tests
uses: coactions/setup-xvfb@v1
with:
run: yarn test
- name: push
run: |
git checkout -b rebase-orig
git push origin/rebase-orig
- name: create pr
run: gh pr create -B main -H rebase-orig --title 'rebase' --body 'Created by Github action'
env:
GITHUB_TOKEN: ${{ github.token }}


3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.3

* support customization of hbs files processing
11 changes: 7 additions & 4 deletions packages/core/src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ export class GlintEnvironment {
* they support.
*/
public getStandaloneTemplateConfig():
| Pick<GlintTemplateConfig, 'typesModule' | 'specialForms'>
| Pick<
GlintTemplateConfig,
'typesModule' | 'specialForms' | 'preprocess' | 'postprocessAst' | 'mapTemplateContent'
>
| undefined {
if (this.standaloneTemplateConfig) {
let { typesModule, specialForms } = this.standaloneTemplateConfig;
return { typesModule, specialForms };
let { typesModule, specialForms, preprocess, postprocessAst, mapTemplateContent } =
this.standaloneTemplateConfig;
return { typesModule, specialForms, preprocess, postprocessAst, mapTemplateContent };
}
}

Expand Down Expand Up @@ -189,7 +193,6 @@ function loadMergedEnvironmentConfig(
}

let config = envFunction(envUserConfig ?? {}) as GlintEnvironmentConfig;

if (config.template) {
if (template) {
throw new SilentError(
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/config/types.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as ts from 'typescript';
import { AST } from '@glimmer/syntax';

// This file is explicitly `.cts` so that environment packages written
// in CJS can import its types from `@glint/core/config-types`.
Expand Down Expand Up @@ -96,6 +97,12 @@ export type PathCandidateWithDeferral = {
};

export type GlintTemplateConfig = {
preprocess?: (
templateInfo: { contents: string; filename: string },
args: { globals?: string[]; preamble?: string[] }
) => { globals: string[]; preamble: string[]; template: string };
postprocessAst?: (ast: AST.Template) => AST.Template;
mapTemplateContent?: Record<string, any>;
typesModule: string;
specialForms?: { [global: string]: GlintSpecialForm };
getPossibleTemplatePaths(scriptPath: string): Array<PathCandidate>;
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/transform/template/inlining/companion-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ export function calculateCompanionTemplateSpans(
return { errors, directives, partialSpans };
}

let { typesModule, specialForms } = templateConfig;
let { typesModule, specialForms, preprocess, postprocessAst, mapTemplateContent } =
templateConfig;
let useJsDoc = environment.isUntypedScript(script.filename);
let targetNode = findCompanionTemplateTarget(ts, ast);
if (targetNode && ts.isClassLike(targetNode)) {
let rewriteResult = templateToTypescript(template.contents, {
let rewriteResult = templateToTypescript(template, {
preprocess,
postprocessAst,
mapTemplateContent,
typesModule,
specialForms,
useJsDoc,
Expand All @@ -56,7 +60,10 @@ export function calculateCompanionTemplateSpans(
: `({} as unknown as typeof import('./${moduleName}').default)`;
}

let rewriteResult = templateToTypescript(template.contents, {
let rewriteResult = templateToTypescript(template, {
preprocess,
postprocessAst,
mapTemplateContent,
typesModule,
backingValue,
specialForms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type EmbeddingSyntax = {

export type MapTemplateContentsOptions = {
embeddingSyntax: EmbeddingSyntax;
postprocessAst?: (ast: AST.Template) => AST.Template;
};

/**
Expand All @@ -128,14 +129,15 @@ export type MapTemplateContentsOptions = {
*/
export function mapTemplateContents(
template: string,
{ embeddingSyntax }: MapTemplateContentsOptions,
{ embeddingSyntax, postprocessAst }: MapTemplateContentsOptions,
callback: (ast: AST.Template | null, mapper: Mapper) => void
): RewriteResult {
let ast: AST.Template | null = null;
let errors: Array<{ message: string; location: Range | undefined }> = [];
let lineOffsets = calculateLineOffsets(template, embeddingSyntax.prefix.length);
try {
ast = preprocess(template);
ast = postprocessAst?.(ast) || ast;
} catch (error) {
let message = getErrorMessage(error);
let location: Range | undefined;
Expand Down

0 comments on commit 760f9a6

Please sign in to comment.