Explorar o código

example: migrate `php-xhr` to ESM (#4009)

Antoine du Hamel %!s(int64=2) %!d(string=hai) anos
pai
achega
655b8ba61b

+ 2 - 1
.eslintrc.js

@@ -195,8 +195,9 @@ module.exports = {
         'examples/aws-presigned-url/*.js',
         'examples/bundled/*.js',
         'examples/custom-provider/client/*.js',
-        'examples/node-xhr/*.js',
         'examples/multiple-instances/*.js',
+        'examples/node-xhr/*.js',
+        'examples/php-xhr/*.js',
         'examples/transloadit-markdown-bin/*.js',
         'examples/xhr-bundle/*.js',
         'private/dev/*.js',

+ 1 - 2
examples/php-xhr/.gitignore

@@ -1,2 +1 @@
-uppy.min.css
-uploads
+uploads/

+ 5 - 5
examples/php-xhr/readme.md → examples/php-xhr/README.md

@@ -6,15 +6,15 @@ This example uses PHP server and `@uppy/xhr-upload` to upload files to the local
 
 To run this example, make sure you've correctly installed the **repository root**:
 
-```bash
-npm install
-npm run build
+```sh
+corepack yarn install
+corepack yarn build
 ```
 
 That will also install the dependencies for this example.
 
 Then, again in the **repository root**, start this example by doing:
 
-```bash
-npm run example php-xhr
+```sh
+corepack yarn workspace @uppy-example/php-xhr start
 ```

+ 1 - 2
examples/php-xhr/index.html

@@ -4,9 +4,8 @@
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <title>PHP + Uppy Example</title>
-    <link href="uppy.min.css" rel="stylesheet">
   </head>
   <body>
-    <script src="bundle.js"></script>
+    <script src="./main.js" type="module"></script>
   </body>
 </html>

+ 8 - 4
examples/php-xhr/main.js

@@ -1,7 +1,11 @@
-const Uppy = require('@uppy/core')
-const Webcam = require('@uppy/webcam')
-const Dashboard = require('@uppy/dashboard')
-const XHRUpload = require('@uppy/xhr-upload')
+import Uppy from '@uppy/core'
+import Webcam from '@uppy/webcam'
+import Dashboard from '@uppy/dashboard'
+import XHRUpload from '@uppy/xhr-upload'
+
+import '@uppy/core/dist/style.css'
+import '@uppy/dashboard/dist/style.css'
+import '@uppy/webcam/dist/style.css'
 
 const uppy = new Uppy({
   debug: true,

+ 9 - 12
examples/php-xhr/package.json

@@ -1,24 +1,21 @@
 {
   "name": "@uppy-example/php-xhr",
   "version": "0.0.0",
+  "type": "module",
   "dependencies": {
-    "@babel/core": "^7.4.4",
     "@uppy/core": "workspace:*",
     "@uppy/dashboard": "workspace:*",
     "@uppy/webcam": "workspace:*",
-    "@uppy/xhr-upload": "workspace:*",
-    "babelify": "^10.0.0",
-    "budo": "^11.3.2",
-    "cookie-parser": "^1.4.6",
-    "cors": "^2.8.4",
-    "formidable": "^1.2.1",
-    "npm-run-all": "^4.1.3"
+    "@uppy/xhr-upload": "workspace:*"
+  },
+  "devDependencies": {
+    "npm-run-all": "^4.1.3",
+    "vite": "^3.0.0"
   },
   "private": true,
   "scripts": {
-    "copy": "cp ../../packages/uppy/dist/uppy.min.css .",
-    "start": "npm-run-all --serial copy --parallel start:*",
-    "start:client": "budo main.js:bundle.js -- -t babelify",
-    "start:server": "mkdir -p uploads && php -S 0.0.0.0:3020"
+    "start": "npm-run-all --parallel start:server start:client",
+    "start:client": "vite",
+    "start:server": "mkdir -p uploads && php -S 0.0.0.0:3020 server.php"
   }
 }

+ 0 - 3
examples/php-xhr/requirements.txt

@@ -1,3 +0,0 @@
-flask
-werkzeug
-flask-cors

+ 5 - 5
examples/php-xhr/upload.php → examples/php-xhr/server.php

@@ -18,14 +18,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
     exit(0);
 }
 
-if ($_POST && !empty($_FILES["files"])) {
-    $target_dir = './uploads/';
-    $target_file = $target_dir . basename($_FILES['files']['name'][0]);
+if ($_POST && !empty($_FILES["file"])) {
+    $target_dir = __DIR__ . DIRECTORY_SEPARATOR . 'uploads';
+    $target_file = $target_dir . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
     try {
-        if (move_uploaded_file($_FILES['files']['tmp_name'][0], $target_file)) {
+        if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {
             header('Access-Control-Allow-Origin: *');
             header('Content-type: application/json');
-            $data = ['url' => $target_file, 'message' => 'The file ' . basename($_FILES['files']['name'][0]) . ' has been uploaded.'];
+            $data = ['url' => $target_file, 'message' => 'The file ' . basename($_FILES['file']['name']) . ' has been uploaded.'];
             http_response_code(201);
             echo json_encode($data);
         } else {

+ 1 - 6
yarn.lock

@@ -8162,17 +8162,12 @@ __metadata:
   version: 0.0.0-use.local
   resolution: "@uppy-example/php-xhr@workspace:examples/php-xhr"
   dependencies:
-    "@babel/core": ^7.4.4
     "@uppy/core": "workspace:*"
     "@uppy/dashboard": "workspace:*"
     "@uppy/webcam": "workspace:*"
     "@uppy/xhr-upload": "workspace:*"
-    babelify: ^10.0.0
-    budo: ^11.3.2
-    cookie-parser: ^1.4.6
-    cors: ^2.8.4
-    formidable: ^1.2.1
     npm-run-all: ^4.1.3
+    vite: ^3.0.0
   languageName: unknown
   linkType: soft