diff --git a/lib-node/index.js b/lib-node/index.js new file mode 100644 index 0000000..575b6a5 --- /dev/null +++ b/lib-node/index.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.initialiseResolver = exports.read_file = void 0; +let resolveFunction = null; +let read_file = function (source_id) { + if (resolveFunction) { + const result = resolveFunction(source_id); + if (typeof result === "string") { + return result; + } + else { + throw new Error("Noir source resolver funtion MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?"); + } + } + else { + throw new Error('Not yet initialised. Use initialiseResolver(() => string)'); + } +}; +exports.read_file = read_file; +function initialise(noir_resolver) { + if (typeof noir_resolver === "function") { + return noir_resolver; + } + else { + throw new Error("Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter"); + } +} +function initialiseResolver(resolver) { + resolveFunction = initialise(resolver); +} +exports.initialiseResolver = initialiseResolver; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib-node/index.js.map b/lib-node/index.js.map new file mode 100644 index 0000000..480b533 --- /dev/null +++ b/lib-node/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,IAAI,eAAe,GAAoB,IAAI,CAAC;AAErC,IAAI,SAAS,GAAG,UAAU,SAAc;IAE3C,IAAI,eAAe,EAAE;QAEjB,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAE1C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC5B,OAAO,MAAM,CAAC;SACjB;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,uHAAuH,CAAC,CAAC;SAC5I;KACJ;SAAM;QACH,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;KAChF;AAEL,CAAC,CAAC;AAfS,QAAA,SAAS,aAelB;AAEF,SAAS,UAAU,CAAC,aAA4C;IAE5D,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;QACrC,OAAO,aAAa,CAAC;KACxB;SAAM;QACH,MAAM,IAAI,KAAK,CAAC,2GAA2G,CAAC,CAAC;KAChI;AACL,CAAC;AAED,SAAgB,kBAAkB,CAAC,QAAuC;IACtE,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC3C,CAAC;AAFD,gDAEC"} \ No newline at end of file diff --git a/lib/index_node.js b/lib-node/index_node.js similarity index 100% rename from lib/index_node.js rename to lib-node/index_node.js diff --git a/lib/index_node.js.map b/lib-node/index_node.js.map similarity index 100% rename from lib/index_node.js.map rename to lib-node/index_node.js.map diff --git a/lib-node/resolver.js b/lib-node/resolver.js new file mode 100644 index 0000000..dec83d3 --- /dev/null +++ b/lib-node/resolver.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.initialiseResolver = exports.read_file = void 0; +let resolveFunction = null; +let read_file = function (source_id) { + if (resolveFunction) { + const result = resolveFunction(source_id); + if (typeof result === "string") { + return result; + } + else { + throw new Error("Noir source resolver funtion MUST return String synchronously. Are you trying to return anything else, eg. `Promise`?"); + } + } + else { + throw new Error('Not yet initialised. Use initialiseResolver(() => string)'); + } +}; +exports.read_file = read_file; +function initialise(noir_resolver) { + if (typeof noir_resolver === "function") { + return noir_resolver; + } + else { + throw new Error("Provided Noir Resolver is not a function, hint: use function(module_id) => NoirSource as second parameter"); + } +} +function initialiseResolver(resolver) { + resolveFunction = initialise(resolver); +} +exports.initialiseResolver = initialiseResolver; +//# sourceMappingURL=resolver.js.map \ No newline at end of file diff --git a/lib-node/resolver.js.map b/lib-node/resolver.js.map new file mode 100644 index 0000000..1937643 --- /dev/null +++ b/lib-node/resolver.js.map @@ -0,0 +1 @@ +{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":";;;AAAA,IAAI,eAAe,GAAoB,IAAI,CAAC;AAErC,IAAI,SAAS,GAAG,UAAU,SAAc;IAE3C,IAAI,eAAe,EAAE;QAEjB,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAE1C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC5B,OAAO,MAAM,CAAC;SACjB;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,uHAAuH,CAAC,CAAC;SAC5I;KACJ;SAAM;QACH,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;KAChF;AAEL,CAAC,CAAC;AAfS,QAAA,SAAS,aAelB;AAEF,SAAS,UAAU,CAAC,aAA4C;IAE5D,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;QACrC,OAAO,aAAa,CAAC;KACxB;SAAM;QACH,MAAM,IAAI,KAAK,CAAC,2GAA2G,CAAC,CAAC;KAChI;AACL,CAAC;AAED,SAAgB,kBAAkB,CAAC,QAAuC;IACtE,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC3C,CAAC;AAFD,gDAEC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index b9d896f..2fa44b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@noir-lang/noir-source-resolver", - "version": "1.1.1", + "version": "1.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@noir-lang/noir-source-resolver", - "version": "1.1.1", + "version": "1.1.3", "license": "MIT", "devDependencies": { "@types/node": "^18.11.17", diff --git a/package.json b/package.json index 4fab68b..102bac7 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "@noir-lang/noir-source-resolver", - "version": "1.1.2", + "version": "1.1.3", "license": "MIT", - "main": "./lib/index_node.js", + "main": "./lib-node/index_node.js", "module": "./lib/index.js", "browser": "./lib/index.js", "exports": { ".": { - "require": "./lib/index_node.js", + "require": "./lib-node/index_node.js", "import": "./lib/index.js" } }, diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index be42d4d..51863a3 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es2018", "moduleResolution": "node", - "outDir": "lib", + "outDir": "lib-node", "module": "commonjs", "strict": true, "esModuleInterop": true,