Skip to content

Commit

Permalink
Extract constants into inlinable package
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Nov 3, 2024
1 parent bda4a4b commit e7d3f87
Show file tree
Hide file tree
Showing 54 changed files with 11,616 additions and 8,884 deletions.
8 changes: 7 additions & 1 deletion packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ export function typescript(pkg, config) {
const EXTERNAL_OPTIONS = [
[
'is',
['tslib', '@glimmer/local-debug-flags', '@glimmer/debug', '@glimmer/debug-util'],
[
'tslib',
'@glimmer/local-debug-flags',
'@glimmer/constants',
'@glimmer/debug',
'@glimmer/debug-util',
],
'inline',
],
['is', ['@handlebars/parser', 'simple-html-tokenizer', 'babel-plugin-debug-macros'], 'external'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import type {
COMMENT_NODE,
DOCUMENT_FRAGMENT_NODE,
DOCUMENT_NODE,
TEXT_NODE,
} from '@glimmer/constants';
import type {
Maybe,
Nullable,
Expand All @@ -10,8 +16,8 @@ import type {
SimpleNode,
SimpleText,
} from '@glimmer/interfaces';
import type { COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, TEXT_NODE } from '@glimmer/util';
import { clearElement, ELEMENT_NODE, INSERT_AFTER_BEGIN } from '@glimmer/util';
import { ELEMENT_NODE, INSERT_AFTER_BEGIN } from '@glimmer/constants';
import { clearElement } from '@glimmer/util';
import Serializer from '@simple-dom/serializer';
import voidMap from '@simple-dom/void-map';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Cursor, ElementBuilder, Environment, SimpleNode } from '@glimmer/interfaces';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/constants';
import { RehydrateBuilder } from '@glimmer/runtime';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/util';

export class DebugRehydrationBuilder extends RehydrateBuilder {
clearedNodes: SimpleNode[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Nullable, SimpleElement, SimpleNode } from '@glimmer/interfaces';
import type { EndTag, Token } from 'simple-html-tokenizer';
import { COMMENT_NODE, TEXT_NODE } from '@glimmer/constants';
import { castToSimple, unwrap } from '@glimmer/debug-util';
import { COMMENT_NODE, TEXT_NODE } from '@glimmer/util';
import { tokenize } from 'simple-html-tokenizer';

import { replaceHTML, toInnerHTML } from './dom/simple-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SimpleElement } from '@glimmer/interfaces';
import { NS_SVG } from '@glimmer/constants';
import { castToBrowser, checkNode, unwrap } from '@glimmer/debug-util';
import { NS_SVG, strip } from '@glimmer/util';
import { strip } from '@glimmer/util';

import { assertNodeTagName } from '../dom/assertions';
import { firstElementChild, getElementsByTagName } from '../dom/simple-utils';
Expand Down
1 change: 1 addition & 0 deletions packages/@glimmer-workspace/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"simple-html-tokenizer": "^0.5.11"
},
"devDependencies": {
"@glimmer/constants": "workspace:*",
"@glimmer/debug-util": "workspace:*",
"@glimmer/local-debug-flags": "workspace:*",
"@types/js-reporters": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SimpleElement } from '@glimmer/interfaces';
import { NS_SVG } from '@glimmer/constants';
import { castToBrowser, expect } from '@glimmer/debug-util';
import { normalizeProperty } from '@glimmer/runtime';
import { NS_SVG } from '@glimmer/util';

import { assertingElement, hasAttribute, jitSuite, RenderTest, test, tracked } from '..';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Dict, Nullable, SimpleElement } from '@glimmer/interfaces';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/constants';
import { castToBrowser, castToSimple, expect } from '@glimmer/debug-util';
import { COMMENT_NODE, ELEMENT_NODE, isObject, LOCAL_LOGGER } from '@glimmer/util';
import { isObject, LOCAL_LOGGER } from '@glimmer/util';

import type { ComponentBlueprint, Content } from '..';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SimpleElement, SimpleNode } from '@glimmer/interfaces';
import type { SafeString } from '@glimmer/runtime';
import { NS_SVG } from '@glimmer/util';
import { NS_SVG } from '@glimmer/constants';

import type { RenderTestConstructor } from '..';
import type RenderDelegate from '../lib/render-delegate';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SimpleElement } from '@glimmer/interfaces';
import { NS_HTML, NS_SVG, NS_XLINK } from '@glimmer/util';
import { NS_HTML, NS_SVG, NS_XLINK } from '@glimmer/constants';

import { assertNodeTagName, jitSuite, RenderTest, test } from '..';
import { assert } from './support';
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export {
unicode,
} from './lib/builder/builder';
export { type BuilderStatement } from './lib/builder/builder-interface';
export * from './lib/builder/constants';
export { defaultId, precompile, precompileJSON, type PrecompileOptions } from './lib/compiler';
export * from '@glimmer/constants';

// exported only for tests!
export { default as WireFormatDebugger } from './lib/wire-format-debug';
10 changes: 4 additions & 6 deletions packages/@glimmer/compiler/lib/builder/builder-interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { VariableKind } from '@glimmer/constants';
import type { Dict, DictValue, Nullable, PresentArray } from '@glimmer/interfaces';
import { expect, isPresentArray } from '@glimmer/debug-util';
import { assertNever, dict } from '@glimmer/util';

import type { VariableKind } from './constants';

import {
APPEND_EXPR_HEAD,
APPEND_PATH_HEAD,
Expand Down Expand Up @@ -37,7 +33,9 @@ import {
MODIFIER_HEAD,
SPLAT_HEAD,
THIS_VAR,
} from './constants';
} from '@glimmer/constants';
import { expect, isPresentArray } from '@glimmer/debug-util';
import { assertNever, dict } from '@glimmer/util';

export type BuilderParams = BuilderExpression[];
export type BuilderHash = Nullable<Dict<BuilderExpression>>;
Expand Down
53 changes: 28 additions & 25 deletions packages/@glimmer/compiler/lib/builder/builder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { VariableKind } from '@glimmer/constants';
import type {
AttrNamespace,
Dict,
Expand All @@ -7,30 +8,6 @@ import type {
PresentArray,
WireFormat,
} from '@glimmer/interfaces';
import { assert, exhausted, expect, isPresentArray } from '@glimmer/debug-util';
import { assertNever, dict, NS_XLINK, NS_XML, NS_XMLNS, values } from '@glimmer/util';
import { SexpOpcodes as Op, VariableResolutionContext } from '@glimmer/wire-format';

import type {
BuilderComment,
BuilderStatement,
NormalizedAngleInvocation,
NormalizedAttrs,
NormalizedBlock,
NormalizedBlocks,
NormalizedElement,
NormalizedExpression,
NormalizedHash,
NormalizedHead,
NormalizedKeywordStatement,
NormalizedParams,
NormalizedPath,
NormalizedStatement,
Variable,
} from './builder-interface';
import type { VariableKind } from './constants';

import { normalizeStatement } from './builder-interface';
import {
APPEND_EXPR_HEAD,
APPEND_PATH_HEAD,
Expand All @@ -55,9 +32,35 @@ import {
LITERAL_HEAD,
LOCAL_VAR,
MODIFIER_HEAD,
NS_XLINK,
NS_XML,
NS_XMLNS,
SPLAT_HEAD,
THIS_VAR,
} from './constants';
} from '@glimmer/constants';
import { assert, exhausted, expect, isPresentArray } from '@glimmer/debug-util';
import { assertNever, dict, values } from '@glimmer/util';
import { SexpOpcodes as Op, VariableResolutionContext } from '@glimmer/wire-format';

import type {
BuilderComment,
BuilderStatement,
NormalizedAngleInvocation,
NormalizedAttrs,
NormalizedBlock,
NormalizedBlocks,
NormalizedElement,
NormalizedExpression,
NormalizedHash,
NormalizedHead,
NormalizedKeywordStatement,
NormalizedParams,
NormalizedPath,
NormalizedStatement,
Variable,
} from './builder-interface';

import { normalizeStatement } from './builder-interface';

interface Symbols {
top: ProgramSymbols;
Expand Down
3 changes: 2 additions & 1 deletion packages/@glimmer/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
},
"devDependencies": {
"@glimmer-workspace/build-support": "workspace:*",
"@glimmer/constants": "workspace:*",
"@glimmer/debug-util": "workspace:*",
"@glimmer/local-debug-flags": "workspace:*",
"@types/node": "^20.9.4",
"eslint": "^8.52.0",
"publint": "^0.2.5",
"rollup": "^4.5.1",
"rollup": "^4.24.3",
"typescript": "*"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions packages/@glimmer/constants/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/
index.ts
3 changes: 3 additions & 0 deletions packages/@glimmer/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './lib/builder-constants';
export * from './lib/dom';
export * from './lib/immediate';
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions packages/@glimmer/constants/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@glimmer/constants",
"private": true,
"version": "0.92.3",
"license": "MIT",
"description": "Constant values and functions that should be inlined and stripped from published builds. This package should not be published.",
"repository": "https://github.com/tildeio/glimmer/tree/main/packages/@glimmer/debug-util",
"type": "module",
"main": "index.ts",
"types": "index.ts",
"publishConfig": {
"access": "public",
"types": "dist/dev/index.d.ts",
"exports": {
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"require": "./dist/dev/index.cjs",
"import": "./dist/dev/index.js"
},
"require": "./dist/dev/index.cjs",
"import": "./dist/prod/index.js"
}
},
"main": null,
"module": "dist/dev/index.js"
},
"files": [
"dist"
],
"scripts": {
"build": "rollup -c rollup.config.mjs",
"test:lint": "eslint .",
"test:publint": "publint",
"test:types": "tsc --noEmit -p ../tsconfig.json"
},
"dependencies": {
"@glimmer/env": "0.1.7",
"@glimmer/interfaces": "workspace:*"
},
"devDependencies": {
"@glimmer-workspace/build-support": "workspace:*",
"@glimmer/debug-util": "workspace:*",
"@glimmer/local-debug-flags": "workspace:*",
"@types/qunit": "^2.19.9",
"eslint": "^8.52.0",
"publint": "^0.2.5",
"rollup": "^4.5.1",
"typescript": "*"
}
}
3 changes: 3 additions & 0 deletions packages/@glimmer/constants/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Package } from '@glimmer-workspace/build-support';

export default Package.config(import.meta);
9 changes: 9 additions & 0 deletions packages/@glimmer/constants/test/debug-to-string-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />

import { BLOCK_HEAD } from '@glimmer/constants';

QUnit.module('@glimmer/constants');

QUnit.test('BLOCK_HEAD', (assert) => {
assert.strictEqual(BLOCK_HEAD, 'Block');
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MAX_SMI,
MIN_INT,
MIN_SMI,
} from '@glimmer/util';
} from '@glimmer/constants';

const { module, test } = QUnit;

Expand Down
13 changes: 13 additions & 0 deletions packages/@glimmer/constants/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "@glimmer-test/constants",
"dependencies": {
"@glimmer/util": "workspace:*",
"@glimmer/env": "0.1.7"
},
"devDependencies": {
"@glimmer/constants": "workspace:*",
"@glimmer/debug-util": "workspace:*",
"vite": "^5.4.10"
}
}
6 changes: 3 additions & 3 deletions packages/@glimmer/debug-util/lib/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export function deprecate(desc: string) {
/**
* This constant exists to make it easier to differentiate normal logs from
* errant console.logs. LOCAL_LOGGER should only be used inside a
* LOCAL_SHOULD_LOG check.
* LOCAL_TRACE_LOGGING check.
*FF
* It does not alleviate the need to check LOCAL_SHOULD_LOG, which is used
* It does not alleviate the need to check LOCAL_TRACE_LOGGING, which is used
* for stripping.
*/
export const LOCAL_LOGGER = console;

/**
* This constant exists to make it easier to differentiate normal logs from
* errant console.logs. LOGGER can be used outside of LOCAL_SHOULD_LOG checks,
* errant console.logs. LOGGER can be used outside of LOCAL_TRACE_LOGGING checks,
* and is meant to be used in the rare situation where a console.* call is
* actually appropriate.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export {
CheckMachineRegister,
CheckMaybe,
CheckNode,
CheckNullable,
CheckNumber,
CheckObject,
CheckNullable,
CheckOr,
CheckPrimitive,
CheckProgramSymbolTable,
Expand Down
3 changes: 2 additions & 1 deletion packages/@glimmer/debug/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import type {
RuntimeOp,
TemplateCompilationContext,
} from '@glimmer/interfaces';
import { decodeHandle, decodeImmediate } from '@glimmer/constants';
import { LOCAL_TRACE_LOGGING } from '@glimmer/local-debug-flags';
import { decodeHandle, decodeImmediate, enumerate, LOCAL_LOGGER } from '@glimmer/util';
import { enumerate, LOCAL_LOGGER } from '@glimmer/util';
import { $fp, $pc, $ra, $s0, $s1, $sp, $t0, $t1, $v0 } from '@glimmer/vm';

import type { Primitive } from './stack-check';
Expand Down
1 change: 1 addition & 0 deletions packages/@glimmer/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"devDependencies": {
"@glimmer-workspace/build-support": "workspace:*",
"@glimmer/constants": "workspace:*",
"@glimmer/debug-util": "workspace:*",
"@glimmer/local-debug-flags": "workspace:*",
"eslint": "^8.52.0",
Expand Down
11 changes: 7 additions & 4 deletions packages/@glimmer/local-debug-flags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ declare global {

// All of these flags are expected to become constant `false` in production builds.
export const LOCAL_DEBUG = import.meta.env.VM_LOCAL_DEV && !hasFlag('disable_local_debug');
export const LOCAL_TRACE_LOGGING = hasFlag('enable_trace_logging');
export const LOCAL_EXPLAIN_LOGGING = hasFlag('enable_trace_explanations');
export const LOCAL_INTERNALS_LOGGING = hasFlag('enable_internals_logging');
export const LOCAL_SUBTLE_LOGGING = hasFlag('enable_subtle_logging');
export const LOCAL_TRACE_LOGGING = import.meta.env.VM_LOCAL_DEV && hasFlag('enable_trace_logging');
export const LOCAL_EXPLAIN_LOGGING =
import.meta.env.VM_LOCAL_DEV && hasFlag('enable_trace_explanations');
export const LOCAL_INTERNALS_LOGGING =
import.meta.env.VM_LOCAL_DEV && hasFlag('enable_internals_logging');
export const LOCAL_SUBTLE_LOGGING =
import.meta.env.VM_LOCAL_DEV && hasFlag('enable_subtle_logging');

if (LOCAL_INTERNALS_LOGGING || LOCAL_EXPLAIN_LOGGING) {
console.group('%cLogger Flags:', 'font-weight: normal; color: teal');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import type {
SingleBuilderOperand,
STDLib,
} from '@glimmer/interfaces';
import { encodeHandle } from '@glimmer/constants';
import { assert, expect, isPresentArray } from '@glimmer/debug-util';
import { InstructionEncoderImpl } from '@glimmer/encoder';
import { dict, EMPTY_STRING_ARRAY, encodeHandle, Stack } from '@glimmer/util';
import { dict, EMPTY_STRING_ARRAY, Stack } from '@glimmer/util';
import { ARG_SHIFT, isMachineOp, MACHINE_MASK, MachineOp, Op, TYPE_SIZE } from '@glimmer/vm';

import { compilableBlock } from '../compilable-template';
Expand Down
Loading

0 comments on commit e7d3f87

Please sign in to comment.