]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Replace angular-cli patch with something less risky (#742)
authorWilliam Lahti <wilahti@gmail.com>
Thu, 28 Jun 2018 13:53:04 +0000 (06:53 -0700)
committerChocobozzz <me@florianbigard.com>
Thu, 28 Jun 2018 13:53:04 +0000 (15:53 +0200)
* Replace angular-cli patch with something less risky

* path.join() is needed, provide a naive implementation

* technically, webpack provided a polyfill for Buffer, we should too

* process polyfill matches webpack; peertube depends on nextTick

* polyfill for path to match webpack

* http/https polyfills as per webpack

client/angular-cli-patch.js [deleted file]
client/package.json
client/src/polyfills.ts
client/src/shims/http.ts [new file with mode: 0644]
client/src/shims/https.ts [new file with mode: 0644]
client/src/shims/noop.ts [new file with mode: 0644]
client/src/shims/path.ts [new file with mode: 0644]
client/tsconfig.json

diff --git a/client/angular-cli-patch.js b/client/angular-cli-patch.js
deleted file mode 100644 (file)
index 0829631..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Remove patch when https://github.com/angular/angular-cli/issues/10681#issuecomment-389160125 is closed
-
-const fs = require('fs');
-const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
-
-fs.readFile(f, 'utf8', function (err,data) {
-  if (err) {
-    return console.log(err);
-  }
-  var result = data.replace(/node: false/g, 'node: { global: true, crypto: "empty", fs: "empty", process: true, module: false, clearImmediate: false, setImmediate: false }');
-
-  fs.writeFile(f, result, 'utf8', function (err) {
-    if (err) return console.log(err);
-  });
-});
index 0c2fdcafe5d7240bbcd7537365768cea0752850e..1264891ec2c048371c619f64b357879c33f17c48 100644 (file)
@@ -17,7 +17,7 @@
     "webpack": "webpack",
     "tslint": "tslint",
     "ng": "ng",
-    "postinstall": "npm rebuild node-sass && test -f angular-cli-patch.js && node angular-cli-patch.js || true",
+    "postinstall": "npm rebuild node-sass",
     "webpack-bundle-analyzer": "webpack-bundle-analyzer",
     "webdriver-manager": "webdriver-manager",
     "ngx-extractor": "ngx-extractor"
@@ -61,6 +61,7 @@
     "angular2-notifications": "^1.0.2",
     "awesome-typescript-loader": "5.0.0",
     "bootstrap-sass": "^3.3.7",
+    "buffer": "^5.1.0",
     "cache-chunk-store": "^2.0.0",
     "codelyzer": "^4.0.2",
     "core-js": "^2.4.1",
@@ -69,6 +70,7 @@
     "extract-text-webpack-plugin": "4.0.0-beta.0",
     "file-loader": "^1.1.5",
     "html-webpack-plugin": "^3.2.0",
+    "https-browserify": "^1.0.0",
     "jasmine-core": "^3.1.0",
     "jasmine-spec-reporter": "^4.2.1",
     "karma": "^2.0.2",
@@ -85,7 +87,9 @@
     "ngx-pipes": "^2.1.7",
     "node-sass": "^4.1.1",
     "npm-font-source-sans-pro": "^1.0.2",
+    "path-browserify": "^1.0.0",
     "primeng": "^6.0.0-rc.1",
+    "process": "^0.11.10",
     "protractor": "^5.3.2",
     "purify-css": "^1.2.5",
     "purifycss-webpack": "^0.7.0",
@@ -95,6 +99,7 @@
     "sanitize-html": "^1.16.3",
     "sass-loader": "^7.0.1",
     "sass-resources-loader": "^1.2.1",
+    "stream-http": "^2.8.3",
     "tslint": "^5.7.0",
     "tslint-config-standard": "^7.0.0",
     "typescript": "2.7",
index 423a7b91589f559649ed309edbf0c04d70b1cf7b..eec30760df211f2c3eee5c31301f5770cc98ef22 100644 (file)
@@ -80,3 +80,9 @@ import 'zone.js/dist/zone'  // Included with Angular CLI.
 /***************************************************************************************************
  * APPLICATION IMPORTS
  */
+
+// global/process polyfills
+
+;(window as any).global = window;
+;(window as any).process = require('process/');
+;(window as any).Buffer = require('buffer/').Buffer;
diff --git a/client/src/shims/http.ts b/client/src/shims/http.ts
new file mode 100644 (file)
index 0000000..a759400
--- /dev/null
@@ -0,0 +1 @@
+module.exports = require('stream-http');
\ No newline at end of file
diff --git a/client/src/shims/https.ts b/client/src/shims/https.ts
new file mode 100644 (file)
index 0000000..1da6f8a
--- /dev/null
@@ -0,0 +1 @@
+module.exports = require('https-browserify');
\ No newline at end of file
diff --git a/client/src/shims/noop.ts b/client/src/shims/noop.ts
new file mode 100644 (file)
index 0000000..338e161
--- /dev/null
@@ -0,0 +1,3 @@
+// Does nothing. Used to shim out node.js modules 
+// which are no-ops in the browser.
+export const NOOP = 0;
\ No newline at end of file
diff --git a/client/src/shims/path.ts b/client/src/shims/path.ts
new file mode 100644 (file)
index 0000000..74b6913
--- /dev/null
@@ -0,0 +1 @@
+module.exports = require('path-browserify');
\ No newline at end of file
index cb6d3924541d572b7b3c09a5eded37074d2fb229..60c343867496496f0b30648622839a5b941f7c11 100644 (file)
     "baseUrl": "src",
     "paths": {
       "@app/*": [ "app/*" ],
-      "video.js": [ "../node_modules/video.js/dist/alt/video.core.js" ]
+      "video.js": [ "../node_modules/video.js/dist/alt/video.core.js" ],
+      "fs": [ "./shims/noop" ],
+      "http": [ "./shims/http" ],
+      "https": [ "./shims/https" ],
+      "path": [ "./shims/path" ],
+      "stream": [ "./shims/noop" ],
+      "crypto": [ "./shims/noop" ]
     }
   }
 }