2.0.28 • Published 3 years ago

src-to-module v2.0.28

Weekly downloads
45
License
Apache-2.0
Repository
github
Last release
3 years ago

src-to-module

npm version

This is a library to load NodeJS script in runtime, either in a file or in plain text.


enableLastModifiedCheck(value: boolean)

Whether to enable last modified check on module cache. Enabled by default. If disabled, will always return cached module.


requireSync(filepath: string, context: any = {})
requireAsync(filepath: string, context: any = {})

Load modules from file.
In case you are using requireAsync, there will be a requireAsync function in global context of the processed file.
Note that using await without async will result to syntax error.
Please check the example.


runSync(code: string, filepath: string, context: any = {})
runAsync(code: string, filepath: string, context: any = {})

Load modules from plain text. A actual/virtual file path should be provided.
In case this is a virtual file path, by default the cache will be expired after 30 mins if a positive maxAge is not provided


registerTranspiler(transpiler: Transpiler)

Register a transpier to transpile and run script.
By default JsTranspiler and JsonTranspiler are registered.


Transpiler

interface Transpiler {
  // check from the file path if the file is valid for this transpiler
  check(path: string): boolean

  // transpile the code to, possibly, JavaScript
  transpile(path: string, code: string): string

  // run the transpiled code
  // you should use the one declared in JsTranspiler
  run<T>(path: string, code: string, require: NodeRequire, baseContext: any): T | undefined

  // run the transpiled code in async context
  // you should use the one declared in JsTranspiler
  runAsync<T>(path: string, code: string, require: NodeRequire, baseContext: any): Promise<T | undefined>
}
2.0.28

3 years ago

2.0.16

3 years ago

2.0.19

3 years ago

2.0.17

3 years ago

2.0.18

3 years ago

2.0.26

3 years ago

2.0.27

3 years ago

2.0.24

3 years ago

2.0.25

3 years ago

2.0.22

3 years ago

2.0.23

3 years ago

2.0.20

3 years ago

2.0.21

3 years ago

2.0.15

3 years ago

2.0.13

3 years ago

2.0.14

3 years ago

2.0.12

3 years ago

2.0.11

3 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-rc.8

4 years ago

1.0.0-rc.7

4 years ago

1.0.0-rc.6

4 years ago

1.0.0-rc.5

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago