Skip to content

Commit

Permalink
fix(nodejs): fix error when using in nodejs env
Browse files Browse the repository at this point in the history
  • Loading branch information
pcholuj committed Mar 25, 2020
1 parent 6f032b5 commit b053360
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 14 deletions.
32 changes: 18 additions & 14 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const MODULE_PREFIX = 'fs-loader-';
const globalHolder: any = {};

export type ModuleDef = {
promise?: Promise<any>
Expand All @@ -14,24 +15,27 @@ export type Namespace = {
};

const initializeGlobalNamespace = () => {
let namespace: Namespace;
let holder = window;

if (typeof window === 'object') {
// @ts-ignore
namespace = window.filestackInternals;
// if there is no window obj use nodejs global lib variable
if (typeof holder !== 'object') {
holder = globalHolder;
}

if (!namespace) {
namespace = {
modules: {},
};
// @ts-ignore
let namespace: Namespace = holder.filestackInternals;

// @ts-ignore
window.filestackInternals = namespace;
}
if (!namespace) {
namespace = {
modules: {},
};

if (!namespace.modules) {
namespace.modules = {};
}
// @ts-ignore
window.filestackInternals = namespace;
}

if (!namespace.modules) {
namespace.modules = {};
}

return namespace;
Expand Down
100 changes: 100 additions & 0 deletions tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"program": {
"fileInfos": {
"./node_modules/typescript/lib/lib.es5.d.ts": {
"version": "b42eddba1a53c9d27279cfe7fc0416c10a81489826ad47e39013b9d340fc0cc7",
"signature": "b42eddba1a53c9d27279cfe7fc0416c10a81489826ad47e39013b9d340fc0cc7"
},
"./node_modules/typescript/lib/lib.es2015.d.ts": {
"version": "7994d44005046d1413ea31d046577cdda33b8b2470f30281fd9c8b3c99fe2d96",
"signature": "7994d44005046d1413ea31d046577cdda33b8b2470f30281fd9c8b3c99fe2d96"
},
"./node_modules/typescript/lib/lib.dom.d.ts": {
"version": "f2039e0dbc31f69183f6377b368c033802dfdcf77e5fd214def06c1fd7b225ed",
"signature": "f2039e0dbc31f69183f6377b368c033802dfdcf77e5fd214def06c1fd7b225ed"
},
"./node_modules/typescript/lib/lib.es2015.core.d.ts": {
"version": "734ddc145e147fbcd55f07d034f50ccff1086f5a880107665ec326fb368876f6",
"signature": "734ddc145e147fbcd55f07d034f50ccff1086f5a880107665ec326fb368876f6"
},
"./node_modules/typescript/lib/lib.es2015.collection.d.ts": {
"version": "4a0862a21f4700de873db3b916f70e41570e2f558da77d2087c9490f5a0615d8",
"signature": "4a0862a21f4700de873db3b916f70e41570e2f558da77d2087c9490f5a0615d8"
},
"./node_modules/typescript/lib/lib.es2015.generator.d.ts": {
"version": "765e0e9c9d74cf4d031ca8b0bdb269a853e7d81eda6354c8510218d03db12122",
"signature": "765e0e9c9d74cf4d031ca8b0bdb269a853e7d81eda6354c8510218d03db12122"
},
"./node_modules/typescript/lib/lib.es2015.iterable.d.ts": {
"version": "285958e7699f1babd76d595830207f18d719662a0c30fac7baca7df7162a9210",
"signature": "285958e7699f1babd76d595830207f18d719662a0c30fac7baca7df7162a9210"
},
"./node_modules/typescript/lib/lib.es2015.promise.d.ts": {
"version": "d4deaafbb18680e3143e8b471acd650ed6f72a408a33137f0a0dd104fbe7f8ca",
"signature": "d4deaafbb18680e3143e8b471acd650ed6f72a408a33137f0a0dd104fbe7f8ca"
},
"./node_modules/typescript/lib/lib.es2015.proxy.d.ts": {
"version": "5e72f949a89717db444e3bd9433468890068bb21a5638d8ab15a1359e05e54fe",
"signature": "5e72f949a89717db444e3bd9433468890068bb21a5638d8ab15a1359e05e54fe"
},
"./node_modules/typescript/lib/lib.es2015.reflect.d.ts": {
"version": "f5b242136ae9bfb1cc99a5971cccc44e99947ae6b5ef6fd8aa54b5ade553b976",
"signature": "f5b242136ae9bfb1cc99a5971cccc44e99947ae6b5ef6fd8aa54b5ade553b976"
},
"./node_modules/typescript/lib/lib.es2015.symbol.d.ts": {
"version": "9ae2860252d6b5f16e2026d8a2c2069db7b2a3295e98b6031d01337b96437230",
"signature": "9ae2860252d6b5f16e2026d8a2c2069db7b2a3295e98b6031d01337b96437230"
},
"./node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts": {
"version": "3e0a459888f32b42138d5a39f706ff2d55d500ab1031e0988b5568b0f67c2303",
"signature": "3e0a459888f32b42138d5a39f706ff2d55d500ab1031e0988b5568b0f67c2303"
},
"./lib/index.ts": {
"version": "6f148b056e32cf4454bfe5693f8e2e4215505267c74dd370487eca1358189696",
"signature": "1224cc0a40563110dbb362a71077cd2ce99a33195fc6b9fdb4d999cc6cad8ee6"
},
"./node_modules/@types/color-name/index.d.ts": {
"version": "f0cb4b3ab88193e3e51e9e2622e4c375955003f1f81239d72c5b7a95415dad3e",
"signature": "f0cb4b3ab88193e3e51e9e2622e4c375955003f1f81239d72c5b7a95415dad3e"
}
},
"options": {
"target": 1,
"module": 1,
"outDir": "./dist",
"rootDir": "./lib",
"inlineSourceMap": true,
"inlineSources": true,
"skipLibCheck": true,
"composite": true,
"declarationMap": true,
"pretty": true,
"baseUrl": "./lib",
"lib": [
"lib.es2015.d.ts",
"lib.dom.d.ts"
],
"project": "./tsconfig.json",
"configFilePath": "./tsconfig.json"
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"./node_modules/typescript/lib/lib.es5.d.ts",
"./node_modules/typescript/lib/lib.es2015.d.ts",
"./node_modules/typescript/lib/lib.dom.d.ts",
"./node_modules/typescript/lib/lib.es2015.core.d.ts",
"./node_modules/typescript/lib/lib.es2015.collection.d.ts",
"./node_modules/typescript/lib/lib.es2015.generator.d.ts",
"./node_modules/typescript/lib/lib.es2015.iterable.d.ts",
"./node_modules/typescript/lib/lib.es2015.promise.d.ts",
"./node_modules/typescript/lib/lib.es2015.proxy.d.ts",
"./node_modules/typescript/lib/lib.es2015.reflect.d.ts",
"./node_modules/typescript/lib/lib.es2015.symbol.d.ts",
"./node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts",
"./node_modules/@types/color-name/index.d.ts",
"./lib/index.ts"
]
},
"version": "3.8.3"
}

0 comments on commit b053360

Please sign in to comment.