Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing ESM version over commonjs, welcome to 2024 #14

Merged
merged 3 commits into from
Apr 4, 2024
Merged
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
File renamed without changes.
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
export default {
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'pegjs', 'glsl'],
modulePathIgnorePatterns: ['src/parser/parser.js'],
testPathIgnorePatterns: ['dist', 'src/parser/parser.js'],
preset: 'ts-jest',
resolver: 'ts-jest-resolver',
// ts-jest is horrifically slow https://github.com/kulshekhar/ts-jest/issues/259#issuecomment-1332269911
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
};
8,891 changes: 5,367 additions & 3,524 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"engines": {
"node": ">=16"
},
"version": "2.1.5",
"version": "3.0.0",
"type": "module",
"description": "A GLSL ES 1.0 and 3.0 parser and preprocessor that can preserve whitespace and comments",
"scripts": {
"prepare": "npm run build && ./prepublish.sh",
Expand Down Expand Up @@ -39,12 +40,15 @@
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@babel/preset-typescript": "^7.15.0",
"@swc/core": "^1.4.11",
"@swc/jest": "^0.2.36",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.2",
"babel-jest": "^27.2.4",
"jest": "^27.0.2",
"jest": "^29.7.0",
"peggy": "^1.2.0",
"prettier": "^2.1.2",
"ts-jest": "^29.1.2",
"ts-jest-resolver": "^2.0.1",
"typescript": "^5.3.3"
}
}
2 changes: 1 addition & 1 deletion src/ast/ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* *AstNode* types where I was lazy or didn't know the core type.
*/

import { Scope } from '../parser/scope';
import { Scope } from '../parser/scope.js';

// The overall result of parsing, which incldues the AST and scopes
export interface Program {
Expand Down
9 changes: 7 additions & 2 deletions src/ast/ast.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { AstNode, BinaryNode, IdentifierNode, LiteralNode } from './ast-types';
import { visit } from './visit';
import {
AstNode,
BinaryNode,
IdentifierNode,
LiteralNode,
} from './ast-types.js';
import { visit } from './visit.js';

const literal = <T>(literal: T): LiteralNode<T> => ({
type: 'literal',
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AstNode, Program } from './ast-types';
import type { AstNode, Program } from './ast-types.js';

type NodeGenerator<NodeType> = (node: NodeType) => string;

Expand Down
6 changes: 3 additions & 3 deletions src/ast/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './ast';
export * from './visit';
export * from './ast-types';
export * from './ast.js';
export * from './visit.js';
export * from './ast-types.js';
2 changes: 1 addition & 1 deletion src/ast/visit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AstNode, Program } from './ast-types';
import type { AstNode, Program } from './ast-types.js';

const isNode = (node: AstNode) => !!node?.type;
const isTraversable = (node: any) => isNode(node) || Array.isArray(node);
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import generate from './parser/generator';
import parser from './parser/parser';
import generate from './parser/generator.js';
import * as parser from './parser/parser.js';

export type * from './error';
export type * from './error.js';

export { generate, parser };
6 changes: 5 additions & 1 deletion src/parser/generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { makeGenerator, makeEveryOtherGenerator, NodeGenerators } from '../ast';
import {
makeGenerator,
makeEveryOtherGenerator,
NodeGenerators,
} from '../ast/index.js';

const generators: NodeGenerators = {
program: (node) => generate(node.wsStart) + generate(node.program),
Expand Down
6 changes: 3 additions & 3 deletions src/parser/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
TypeNameNode,
FullySpecifiedTypeNode,
TypeSpecifierNode,
} from '../ast';
import { ParserOptions } from './parser';
} from '../ast/index.js';
import { ParserOptions } from './parser.js';
import {
Scope,
findGlobalScope,
Expand All @@ -30,7 +30,7 @@ import {
isDeclaredType,
makeScopeIndex,
findBindingScope,
} from './scope';
} from './scope.js';

export {
Scope,
Expand Down
6 changes: 3 additions & 3 deletions src/parser/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FunctionCallNode, visit } from '../ast';
import { GlslSyntaxError } from '../error';
import { buildParser } from './test-helpers';
import { FunctionCallNode, visit } from '../ast/index.js';
import { GlslSyntaxError } from '../error.js';
import { buildParser } from './test-helpers.js';

let c!: ReturnType<typeof buildParser>;
beforeAll(() => (c = buildParser()));
Expand Down
16 changes: 8 additions & 8 deletions src/parser/scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import generate from './generator';
import { renameBindings, renameFunctions, renameTypes } from './utils';
import { UNKNOWN_TYPE } from './grammar';
import { buildParser, nextWarn } from './test-helpers';
import generate from './generator.js';
import { renameBindings, renameFunctions, renameTypes } from './utils.js';
import { UNKNOWN_TYPE } from './grammar.js';
import { buildParser, nextWarn } from './test-helpers.js';

let c!: ReturnType<typeof buildParser>;
beforeAll(() => (c = buildParser()));
Expand Down Expand Up @@ -409,7 +409,7 @@ void x() {
expect(ast.scopes[0].types).toMatchObject({});
// Should have found one overload signature
expect(ast.scopes[0].functions).toHaveProperty('main');
expect(ast.scopes[0].functions.main).toHaveProperty(signature);
expect(ast.scopes[0].functions.main).toHaveProperty([signature]);
expect(Object.keys(ast.scopes[0].functions.main)).toHaveLength(1);
// Should be declared with references
expect(ast.scopes[0].functions.main[signature].declaration).toBeTruthy();
Expand Down Expand Up @@ -474,9 +474,9 @@ void x() {
// undefined, and one for the unknown call
expect(ast.scopes[0].functions).toHaveProperty('main');
expect(Object.keys(ast.scopes[0].functions.main)).toHaveLength(3);
expect(ast.scopes[0].functions.main).toHaveProperty(defSig);
expect(ast.scopes[0].functions.main).toHaveProperty(undefSig);
expect(ast.scopes[0].functions.main).toHaveProperty(unknownSig);
expect(ast.scopes[0].functions.main).toHaveProperty([defSig]);
expect(ast.scopes[0].functions.main).toHaveProperty([undefSig]);
expect(ast.scopes[0].functions.main).toHaveProperty([unknownSig]);

// Defined function has prototype, definition
expect(ast.scopes[0].functions.main[defSig].declaration).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions src/parser/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
FunctionNode,
FunctionCallNode,
TypeNameNode,
} from '../ast';
import { xor } from './utils';
} from '../ast/index.js';
import { xor } from './utils.js';

export type TypeScopeEntry = {
declaration?: TypeNameNode;
Expand Down
8 changes: 4 additions & 4 deletions src/parser/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { execSync } from 'child_process';
import { GrammarError } from 'peggy';
import util from 'util';
import generate from './generator';
import { AstNode, FunctionNode, Program } from '../ast';
import { Parse, ParserOptions } from './parser';
import { FunctionScopeIndex, Scope, ScopeIndex } from './scope';
import generate from './generator.js';
import { AstNode, FunctionNode, Program } from '../ast/index.js';
import { Parse, ParserOptions } from './parser.js';
import { FunctionScopeIndex, Scope, ScopeIndex } from './scope.js';

export const inspect = (arg: any) =>
console.log(util.inspect(arg, false, null, true));
Expand Down
4 changes: 2 additions & 2 deletions src/parser/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AstNode } from '../ast';
import { Scope } from './scope';
import type { AstNode } from '../ast/index.js';
import { Scope } from './scope.js';

export const renameBindings = (
scope: Scope,
Expand Down
6 changes: 3 additions & 3 deletions src/preprocessor/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { makeGenerator, NodeGenerators } from '../ast';
import { PreprocessorProgram } from './preprocessor';
import { PreprocessorAstNode } from './preprocessor-node';
import { makeGenerator, NodeGenerators } from '../ast/index.js';
import { PreprocessorProgram } from './preprocessor.js';
import { PreprocessorAstNode } from './preprocessor-node.js';

type NodeGenerator<NodeType> = (node: NodeType) => string;

Expand Down
6 changes: 3 additions & 3 deletions src/preprocessor/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import generate from './generator';
import generate from './generator.js';
import {
preprocessAst,
preprocessComments,
PreprocessorOptions,
} from './preprocessor';
} from './preprocessor.js';

// This index file is currently only for package publishing, where the whole
// library exists in the dist/ folder, so the below import is relative to dist/
import parser from './preprocessor-parser.js';
import * as parser from './preprocessor-parser.js';

// Should this be in a separate file? There's no tests for it either
const preprocess = (src: string, options: PreprocessorOptions) =>
Expand Down
6 changes: 3 additions & 3 deletions src/preprocessor/preprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
preprocessComments,
preprocessAst,
PreprocessorProgram,
} from './preprocessor';
import generate from './generator';
import { GlslSyntaxError } from '../error';
} from './preprocessor.js';
import generate from './generator.js';
import { GlslSyntaxError } from '../error.js';

const fileContents = (filePath: string): string =>
fs.readFileSync(filePath).toString();
Expand Down
4 changes: 2 additions & 2 deletions src/preprocessor/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NodeVisitor, Path, visit } from '../ast/visit';
import { NodeVisitor, Path, visit } from '../ast/visit.js';
import {
PreprocessorAstNode,
PreprocessorElseIfNode,
PreprocessorIdentifierNode,
PreprocessorIfNode,
PreprocessorLiteralNode,
PreprocessorSegmentNode,
} from './preprocessor-node';
} from './preprocessor-node.js';

export type PreprocessorProgram = {
type: string;
Expand Down
88 changes: 17 additions & 71 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,28 @@
// window.location, when in fact it's peggy's location() function.
"lib": ["ESNext"],

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// Create ESM modules
"module": "NodeNext",
// Specify multiple folders that act like `./node_modules/@types`
"typeRoots": [
"node_modules/@types",
"./preprocessor",
"./parser"
], /* Specify multiple folders that act like `./node_modules/@types`. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
],

/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
"moduleResolution": "NodeNext",

/* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
// Generate .d.ts files from TypeScript and JavaScript files in your project
"declaration": true,
// Specify an output folder for all emitted files.
"outDir": "./dist",
// Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"esModuleInterop": true,
// Ensure that casing is correct in imports
"forceConsistentCasingInFileNames": true,
// Enable all strict type-checking options.
"strict": true,
// Skip type checking all .d.ts files
"skipLibCheck": true
}
}
Loading