Skip to content

Commit

Permalink
chore: add examples on how to use it with import assertions (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
artberri committed Oct 2, 2024
1 parent 9817fa9 commit 4cc80b9
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
**/.DS_Store
8 changes: 8 additions & 0 deletions examples/karma-ts/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const istanbul = require("rollup-plugin-istanbul")
const typescript = require("@rollup/plugin-typescript")
const json = require("@rollup/plugin-json")

module.exports = (config) => {
config.set({
Expand All @@ -25,11 +26,18 @@ module.exports = (config) => {
rollupPreprocessor: {
plugins: [
typescript(),
json(),
istanbul({
exclude: ["spec/**/*.spec.ts"],
sourceMap: true,
instrumenterConfig: {
produceSourceMap: true,
parserPlugins: [
["importAttributes", { deprecatedAssertSyntax: true }],
],
generatorOpts: {
importAttributesKeyword: "assert",
},
},
}),
],
Expand Down
1 change: 1 addition & 0 deletions examples/karma-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"license": "MIT",
"devDependencies": {
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-typescript": "^12.1.0",
"@types/chai": "^4.3.20",
"@types/mocha": "^10.0.8",
Expand Down
18 changes: 18 additions & 0 deletions examples/karma-ts/pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion examples/karma-ts/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json from "@rollup/plugin-json"
import typescript from "@rollup/plugin-typescript"

export default {
Expand All @@ -17,5 +18,5 @@ export default {
file: "./dist/example.cjs.js",
},
],
plugins: [typescript()],
plugins: [typescript(), json()],
}
3 changes: 3 additions & 0 deletions examples/karma-ts/src/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"json": true
}
6 changes: 6 additions & 0 deletions examples/karma-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { sum } from "./sum"

import data from "./data.json" assert { type: "json" }

interface Example {
sum(a: number, b: number): number
subtract(a: number, b: number): number
Expand All @@ -25,3 +27,7 @@ export const example: Example = {
return multiply(a, b)
},
}

export const logData = () => {
console.log(data)
}
6 changes: 3 additions & 3 deletions examples/karma-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
/* Modules */
"module": "esnext" /* 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. */
"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. */
// "typeRoots": [], /* 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. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
"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 */
Expand All @@ -52,7 +52,7 @@
// "outDir": "./", /* 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. */
"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. */
Expand Down

0 comments on commit 4cc80b9

Please sign in to comment.