2.0.28 • Published 4 years ago

src-to-module v2.0.28

Weekly downloads
45
License
Apache-2.0
Repository
github
Last release
4 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

4 years ago

2.0.16

4 years ago

2.0.19

4 years ago

2.0.17

4 years ago

2.0.18

4 years ago

2.0.26

4 years ago

2.0.27

4 years ago

2.0.24

4 years ago

2.0.25

4 years ago

2.0.22

4 years ago

2.0.23

4 years ago

2.0.20

4 years ago

2.0.21

4 years ago

2.0.15

4 years ago

2.0.13

4 years ago

2.0.14

4 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.6

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-rc.8

5 years ago

1.0.0-rc.7

5 years ago

1.0.0-rc.6

5 years ago

1.0.0-rc.5

5 years ago

1.0.0-rc.4

5 years ago

1.0.0-rc.3

5 years ago

1.0.0-rc.2

5 years ago

1.0.0-rc.1

5 years ago