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

Use Node 16 module resolution #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions docs/akte.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { defineAkteApp } from "akte";

import { version } from "../package.json";

import { pages } from "./files/pages";
import { sitemap } from "./files/sitemap";
import { pages } from "./files/pages.js";
import { sitemap } from "./files/sitemap.js";

export const app = defineAkteApp({
files: [pages, sitemap],
Expand Down
10 changes: 3 additions & 7 deletions docs/akte/markdownToHTML.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Plugin, type Processor, unified } from "unified";
import { type Plugin, type Processor, unified, } from "unified";

import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
Expand All @@ -10,15 +10,11 @@ import remarkRehype from "remark-rehype";

import rehypeSlug from "rehype-slug";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeToc from "rehype-toc";
import rehypeToc, { type Options as RehypeTocOptions } from "rehype-toc";
import rehypeStringify from "rehype-stringify";

import { common, createStarryNight } from "@wooorm/starry-night";

// @ts-expect-error - Cannot resolve type
import ignoreGrammar from "@wooorm/starry-night/source.gitignore";

// @ts-expect-error - Cannot resolve type
import tsxGrammar from "@wooorm/starry-night/source.tsx";
import { visit } from "unist-util-visit";
import { toString } from "hast-util-to-string";
Expand Down Expand Up @@ -177,7 +173,7 @@ export const markdownToHTML = async <TMatter extends Record<string, unknown>>(

.use(rehypeSlug)
.use(rehypeAutolinkHeadings, { behavior: "wrap" })
.use(rehypeToc, {
.use(rehypeToc as unknown as Plugin<[RehypeTocOptions]>, {
headings: ["h2", "h3"],
cssClasses: {
list: "",
Expand Down
4 changes: 2 additions & 2 deletions docs/files/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as fs from "node:fs/promises";
import { defineAkteFiles } from "akte";
import { globby } from "globby";

import { markdownToHTML } from "../akte/markdownToHTML";
import { base } from "../layouts/base";
import { markdownToHTML } from "../akte/markdownToHTML.js";
import { base } from "../layouts/base.js";

const contentDir = path.resolve(__dirname, "../content");

Expand Down
8 changes: 4 additions & 4 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"strict": true,
"skipLibCheck": true,

"target": "esnext",
"module": "esnext",
"target": "ES2022",
"module": "Node16",
"declaration": false,
"moduleResolution": "node",
"moduleResolution": "Node16",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,

"forceConsistentCasingInFileNames": true,
"jsx": "preserve",
"lib": ["esnext", "dom"],
"lib": ["ES2023", "DOM"],
"types": ["node"]
},
"exclude": ["node_modules", "dist", "examples"]
Expand Down
2 changes: 1 addition & 1 deletion docs/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "vite";
import akte from "akte/vite";

import { app } from "./akte.app";
import { app } from "./akte.app.js";

export default defineConfig({
build: {
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions playground/akte.app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineAkteApp } from "akte";

import { index } from "./src/pages/index";
import { sitemap } from "./src/pages/sitemap";
import { postsSlug } from "./src/pages/posts/slug";
import { catchAll } from "./src/pages/catchAll";
import { index } from "./src/pages/index.js";
import { sitemap } from "./src/pages/sitemap.js";
import { postsSlug } from "./src/pages/posts/slug.js";
import { catchAll } from "./src/pages/catchAll/index.js";

export const app = defineAkteApp({
// files: [],
Expand Down
4 changes: 2 additions & 2 deletions playground/src/pages/catchAll/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineAkteFiles } from "akte";
import { basic } from "../../layouts/basic";
import { basic } from "../../layouts/basic.js";

export const catchAll = defineAkteFiles().from({
export const catchAll = defineAkteFiles<unknown>().from({
path: "/catch-all/**",
bulkData() {
return {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineAkteFile } from "akte";
import { basic } from "../layouts/basic";
import { basic } from "../layouts/basic.js";

export const index = defineAkteFile().from({
export const index = defineAkteFile<unknown, number>().from({
path: "/",
async data() {
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down
2 changes: 1 addition & 1 deletion playground/src/pages/posts/slug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type PrismicDocument, createClient } from "@prismicio/client";
import fetch from "node-fetch";

import { defineAkteFiles } from "akte";
import { basic } from "../../layouts/basic";
import { basic } from "../../layouts/basic.js";

const client = createClient("lihbr", {
routes: [
Expand Down
2 changes: 1 addition & 1 deletion playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "vite";
import akte from "akte/vite";

import { app } from "./akte.app";
import { app } from "./akte.app.js";

export default defineConfig({
root: "src",
Expand Down
22 changes: 11 additions & 11 deletions src/AkteApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { mkdir, writeFile } from "node:fs/promises";

import { type MatchedRoute, type RadixRouter, createRouter } from "radix3";

import type { AkteFiles } from "./AkteFiles";
import type { Awaitable, GlobalDataFn } from "./types";
import { NotFoundError } from "./errors";
import { runCLI } from "./runCLI";
import { akteWelcome } from "./akteWelcome";
import type { AkteFiles } from "./AkteFiles.js";
import type { Awaitable, GlobalDataFn } from "./types.js";
import { NotFoundError } from "./errors.js";
import { runCLI } from "./runCLI.js";
import { akteWelcome } from "./akteWelcome.js";

import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
import { createDebugger } from "./lib/createDebugger";
import { pathToRouterPath } from "./lib/pathToRouterPath";
import { isCLI } from "./lib/isCLI";
import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
import { createDebugger } from "./lib/createDebugger.js";
import { pathToRouterPath } from "./lib/pathToRouterPath.js";
import { isCLI } from "./lib/isCLI.js";

/* eslint-disable @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports */

import type { defineAkteFile } from "./defineAkteFile";
import type { defineAkteFiles } from "./defineAkteFiles";
import type { defineAkteFile } from "./defineAkteFile.js";
import type { defineAkteFiles } from "./defineAkteFiles.js";

/* eslint-enable @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports */

Expand Down
12 changes: 6 additions & 6 deletions src/AkteFiles.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { NotFoundError } from "./errors";
import { type Awaitable } from "./types";
import { NotFoundError } from "./errors.js";
import { type Awaitable } from "./types.js";

import { createDebugger } from "./lib/createDebugger";
import { pathToFilePath } from "./lib/pathToFilePath";
import { toReadonlyMap } from "./lib/toReadonlyMap";
import { createDebugger } from "./lib/createDebugger.js";
import { pathToFilePath } from "./lib/pathToFilePath.js";
import { toReadonlyMap } from "./lib/toReadonlyMap.js";

/* eslint-disable @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports */

import type { AkteApp } from "./AkteApp";
import type { AkteApp } from "./AkteApp.js";

/* eslint-enable @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports */

Expand Down
6 changes: 3 additions & 3 deletions src/akteWelcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as fs from "node:fs/promises";
import * as path from "node:path";
import { createRequire } from "node:module";

import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
import { defineAkteFiles } from "./defineAkteFiles";
import { NotFoundError } from "./errors";
import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
import { defineAkteFiles } from "./defineAkteFiles.js";
import { NotFoundError } from "./errors.js";

/**
* Akte welcome page shown in development when the Akte app does not have any
Expand Down
2 changes: 1 addition & 1 deletion src/defineAkteApp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AkteApp, type Config } from "./AkteApp";
import { AkteApp, type Config } from "./AkteApp.js";

/**
* Creates an Akte app from given configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/defineAkteFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
type FilesBulkDataFn,
type FilesDataFn,
type FilesDefinition,
} from "./AkteFiles";
import type { Empty } from "./types";
} from "./AkteFiles.js";
import type { Empty } from "./types.js";

type FileDefinition<TGlobalData, TData> = Omit<
FilesDefinition<TGlobalData, never[], TData>,
Expand Down
4 changes: 2 additions & 2 deletions src/defineAkteFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
type FilesBulkDataFn,
type FilesDataFn,
type FilesDefinition,
} from "./AkteFiles";
} from "./AkteFiles.js";

import type { Empty } from "./types";
import type { Empty } from "./types.js";

/**
* Creates an Akte files instance.
Expand Down
18 changes: 11 additions & 7 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
export class NotFoundError extends Error {
path: string;

// This property already exists on Error, but TypeScript is unaware
declare cause?: unknown;

constructor(
path: string,
options?: {
cause?: unknown;
},
) {
if (!options?.cause) {
super(`Could lookup file for path \`${path}\``, options);
} else {
super(
`Could lookup file for path \`${path}\`\n\n${options.cause.toString()}`,
options,
);
const cause = options?.cause;
let message = `Could lookup file for path \`${path}\``;

if (cause) {
message += `\n\n${cause.toString()}`;
}

// @ts-expect-error - TypeScript doesn't know Node 16 has the two argument Error constructor
super(message, options);

this.path = path;
}
}
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export type { Config, AkteApp } from "./AkteApp";
export type { AkteFiles } from "./AkteFiles";
export type { Config, AkteApp } from "./AkteApp.js";
export type { AkteFiles } from "./AkteFiles.js";

export { defineAkteApp } from "./defineAkteApp";
export { defineAkteFile } from "./defineAkteFile";
export { defineAkteFiles } from "./defineAkteFiles";
export { defineAkteApp } from "./defineAkteApp.js";
export { defineAkteFile } from "./defineAkteFile.js";
export { defineAkteFiles } from "./defineAkteFiles.js";

export { NotFoundError } from "./errors";
export { NotFoundError } from "./errors.js";
4 changes: 2 additions & 2 deletions src/lib/createDebugger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import debug from "debug";
import { hasHelp, hasSilent, hasVersion } from "./hasFlag";
import { isCLI } from "./isCLI";
import { hasHelp, hasSilent, hasVersion } from "./hasFlag.js";
import { isCLI } from "./isCLI.js";

type DebuggerFn = (msg: unknown, ...args: unknown[]) => void;
type Debugger = DebuggerFn & {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hasFlag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commandsAndFlags } from "./commandsAndFlags";
import { commandsAndFlags } from "./commandsAndFlags.js";

const hasFlag = (...flags: string[]): boolean => {
for (const flag of flags) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pathToRouterPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFilePath } from "./pathToFilePath";
import { pathToFilePath } from "./pathToFilePath.js";

export const pathToRouterPath = (path: string): string => {
const filePath = pathToFilePath(path);
Expand Down
10 changes: 5 additions & 5 deletions src/runCLI.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type AkteApp } from "./AkteApp";
import { type AkteApp } from "./AkteApp.js";

import { commandsAndFlags } from "./lib/commandsAndFlags";
import { createDebugger } from "./lib/createDebugger";
import { hasHelp, hasVersion } from "./lib/hasFlag";
import { pkg } from "./lib/pkg";
import { commandsAndFlags } from "./lib/commandsAndFlags.js";
import { createDebugger } from "./lib/createDebugger.js";
import { hasHelp, hasVersion } from "./lib/hasFlag.js";
import { pkg } from "./lib/pkg.js";

const debugCLI = createDebugger("akte:cli");

Expand Down
6 changes: 3 additions & 3 deletions src/vite/AkteViteCache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { dirname, resolve } from "node:path";
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";

import type { AkteFiles } from "../AkteFiles";
import { type Awaitable } from "../types";
import { pathToFilePath } from "../lib/pathToFilePath";
import type { AkteFiles } from "../AkteFiles.js";
import { type Awaitable } from "../types.js";
import { pathToFilePath } from "../lib/pathToFilePath.js";

const GLOBAL_DATA = "app.globalData";
const DATA = "file.data";
Expand Down
8 changes: 4 additions & 4 deletions src/vite/aktePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type PluginOption } from "vite";

import { createDebugger } from "../lib/createDebugger";
import { serverPlugin } from "./plugins/serverPlugin";
import { buildPlugin } from "./plugins/buildPlugin";
import type { Options, ResolvedOptions } from "./types";
import { createDebugger } from "../lib/createDebugger.js";
import { serverPlugin } from "./plugins/serverPlugin.js";
import { buildPlugin } from "./plugins/buildPlugin.js";
import type { Options, ResolvedOptions } from "./types.js";

const MINIFY_HTML_DEFAULT_OPTIONS = {
collapseBooleanAttributes: true,
Expand Down
2 changes: 1 addition & 1 deletion src/vite/createAkteViteCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AkteViteCache } from "./AkteViteCache";
import { AkteViteCache } from "./AkteViteCache.js";

export const createAkteViteCache = (root: string): AkteViteCache => {
return new AkteViteCache(root);
Expand Down
4 changes: 2 additions & 2 deletions src/vite/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { aktePlugin } from "./aktePlugin";
import { aktePlugin } from "./aktePlugin.js";

export default aktePlugin;
export type { Options } from "./types";
export type { Options } from "./types.js";
8 changes: 4 additions & 4 deletions src/vite/plugins/buildPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { existsSync } from "node:fs";

import type { Plugin } from "vite";

import type { ResolvedOptions } from "../types";
import { createAkteViteCache } from "../createAkteViteCache";
import { pkg } from "../../lib/pkg";
import { createDebugger } from "../../lib/createDebugger";
import type { ResolvedOptions } from "../types.js";
import { createAkteViteCache } from "../createAkteViteCache.js";
import { pkg } from "../../lib/pkg.js";
import { createDebugger } from "../../lib/createDebugger.js";

let isServerRestart = false;

Expand Down
Loading